forked from sanskarchand/bone-animator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtk_main.py
More file actions
68 lines (45 loc) · 1.71 KB
/
tk_main.py
File metadata and controls
68 lines (45 loc) · 1.71 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
62
63
64
65
66
67
68
#!/usr/bin/env python
import tkinter as tk
import pygame as pg
import Bone, const
import os
class MainApplication:
def __init__(self):
self.running = True
self.mouse_pos = (0, 0)
self.root = tk.Tk()
self.embed = tk.Frame(self.root, width=const.PYGAME_DIM[0],
height=const.PYGAME_DIM[1])
self.embed.pack(side="right")
#Tell pygame's SDL window the window ID to be used
os.environ["SDL_WINDOWID"] = str(self.embed.winfo_id())
#for WINDOWS
#os.environ["SDL_VIDEODRIVER"] = "windib"
self.root.update() # assign ID by showing
self.figure_def = Bone.Figure.fromFile("man_figure.xml")
pg.init()
self.main_screen = pg.display.set_mode(const.PYGAME_DIM)
self.clock = pg.time.Clock()
self.createWidgets()
def createWidgets(self):
self.button = tk.Button(self.root)
self.button["text"] = "FUCK THIS"
self.button.pack(side="left")
def mainLoop(self):
while self.running:
for event in pg.event.get():
if event.type == pg.QUIT:
self.running = False
if event.type == pg.KEYDOWN:
print("KEY PRESSED")
if event.type == pg.MOUSEBUTTONDOWN:
print("MOUSE BUTTON DOWN")
self.figure_def.checkPressed(self.mouse_pos)
self.mouse_pos = pg.mouse.get_pos()
self.main_screen.fill(const.BGCOLOR)
self.figure_def.draw(self.main_screen)
pg.display.update()
self.clock.tick(const.FPS)
self.root.update()
m_app = MainApplication()
m_app.mainLoop()