-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
71 lines (54 loc) · 1.59 KB
/
gui.py
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
69
70
71
import tkinter as tk
from PIL import ImageTk, Image
import sys
import os
# Setup tkinter
window = tk.Tk()
window.title("Rebound Predictor Tool")
# Include all code from shotLocation.py
def runSimulation():
print("TEST")
# Icon
window.iconbitmap('./assets/hockey.ico')
# Display image
rink = tk.PhotoImage(file="./assets/HockeyRinkZone.png")
labelRink = tk.Label(image=rink)
labelRink.pack()
# Set up button(s)
label = tk.Button(window, text = "No functionality here yet", command=runSimulation()).pack()
# Define globals
puckLocationX = 0
puckLocationY = 0
puckPlaced = False
# Display x-y of mouse
# Will use this to detect where puck is placed
def motion(event):
x, y = event.x, event.y
print('{}, {}'.format(x, y))
# Show puck on interface at desired position
def onClick(event):
global puckLocationX, puckLocationY
print ("Clicked at", event.x, event.y)
puckLocationX, puckLocationY = event.x, event.y
load = Image.open("./assets/puck.png")
render = ImageTk.PhotoImage(load)
img = tk.Label(window, image=render)
img.image = render
img.place(x=puckLocationX-10, y=puckLocationY-10)
puckPlaced = True
def checkKeyPress(event):
print ("Pressed", repr(event.char))
if (event.char == 'q'):
restart()
elif (event.char == '\r'):
runSimulation()
else:
print(puckLocationX, puckLocationY)
def restart():
print("TEST")
os.execl(sys.executable, sys.executable, *sys.argv)
window.bind('<Motion>', motion)
window.bind('<Button-1>', onClick)
window.bind("<Key>", checkKeyPress)
window.geometry("+600+300")
window.mainloop()