-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathmain_tkinter.py
More file actions
61 lines (46 loc) · 1.52 KB
/
Copy pathmain_tkinter.py
File metadata and controls
61 lines (46 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# usage with tkinter
import os.path
import tkinter
import pyautogui
from pyopengltk import OpenGLFrame
import resources
from time import sleep
import live2d
LIVE2D_VERSION = 2
class AppOgl(OpenGLFrame):
def __init__(self, master, **kw):
super().__init__(master, **kw)
self.model = None
def initgl(self):
"""Initalize gl states when the frame is created"""
if self.model:
del self.model
live2d.dispose()
live2d.init()
live2d.glInit()
self.model = live2d.Model()
if LIVE2D_VERSION == 2:
self.model.LoadModelJson(os.path.join(resources.RESOURCES_DIRECTORY, "v2/kasumi2/kasumi2.model.json"))
else:
self.model.LoadModelJson(os.path.join(resources.RESOURCES_DIRECTORY, "v3/haru/haru.model3.json"))
self.model.Resize(self.width, self.height)
def redraw(self):
"""Render a single frame"""
live2d.clearBuffer()
screen_x, screen_y = pyautogui.position()
x = screen_x - self.winfo_rootx()
y = screen_y - self.winfo_rooty()
self.model.Update()
self.model.Drag(x, y)
self.model.Draw()
# 控制帧率
sleep(1 / 60)
if __name__ == '__main__':
root = tkinter.Tk()
root.attributes('-transparent', 'black')
app = AppOgl(root, width=400, height=500)
root.bind("<Button-1>", lambda _: app.model.StartRandomMotion())
app.pack(fill=tkinter.BOTH, expand=tkinter.YES)
app.animate = 1
app.mainloop()
live2d.dispose()