-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTkinterWindow.py
More file actions
69 lines (56 loc) · 2 KB
/
TkinterWindow.py
File metadata and controls
69 lines (56 loc) · 2 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
69
from tkinter import *
class App(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
#Setup Menu
MainMenu(self)
#Setup Frame
container = Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, context):
frame = self.frames[context]
frame.tkraise()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text="Start Page")
label.pack(padx=10, pady=10)
page_one = Button(self, text="Page One", command=lambda:controller.show_frame(PageOne))
page_one.pack()
page_two = Button(self, text="Page Two", command=lambda:controller.show_frame(PageTwo))
page_two.pack()
class PageOne(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text="Page One")
label.pack(padx=10, pady=10)
start_page = Button(self, text="Start Page", command=lambda:controller.show_frame(StartPage))
start_page.pack()
page_two = Button(self, text="Page Two", command=lambda:controller.show_frame(PageTwo))
page_two.pack()
class PageTwo(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text="Page Two")
label.pack(padx=10, pady=10)
start_page = Button(self, text="Start Page", command=lambda:controller.show_frame(StartPage))
start_page.pack()
page_one = Button(self, text="Page One", command=lambda:controller.show_frame(PageOne))
page_one.pack()
class MainMenu:
def __init__(self, master):
menubar = Menu(master)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Exit", command=master.quit)
menubar.add_cascade(label="File", menu=filemenu)
master.config(menu=menubar)
app = App()
app.mainloop()