-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainGUI.py
76 lines (57 loc) · 2.44 KB
/
MainGUI.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
72
73
74
75
76
import tkinter as tk
from GUIs.StatGUI import StatGUI, populateUIStat
from GUIs.GameGUI import GameGUI, populateUIGame
class WindowLauncher(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
global root
root = self
self.minsize(800, 600)
self.grid_columnconfigure(0, weight=1)
container = tk.Frame(self)
container.grid_columnconfigure(0, weight=1) # centers the GUI
container.grid(row=0, column=0)
self.frames = {}
for F in (MainMenuUI, GameGUI, StatGUI):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("MainMenuUI")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()
class MainMenuUI(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
global controller1
controller1 = controller
self.parent = parent
title = tk.Label(self, text='Hangman Game', font=('Arial', 27))
title.grid(row=0, column=0, pady=(8, 20))
introduction = tk.Label(self, text='Please choose the following option:', bg='gold')
introduction.grid(row=1, column=0, sticky='EW')
start = tk.Button(self, text='Start the game', fg='red', command=gameLauncher)
start.grid(row=2, column=0, pady=(16, 0))
self.rowconfigure(1, weight=1)
stats = tk.Button(self, text='View stats (coming soon)', fg='blue', command=statLauncher)
stats.grid(row=3, column=0, pady=(8, 0))
self.rowconfigure(2, weight=1)
exitB = tk.Button(self, text='Exit', fg='green', bg='black', command=root.destroy)
exitB.grid(row=4, column=0, pady=(8, 0))
def gameLauncher():
populateUIGame()
controller1.show_frame("GameGUI")
def statLauncher():
populateUIStat()
controller1.show_frame("StatGUI")
if __name__ == "__main__":
app = WindowLauncher()
app.mainloop()