Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Tkinter as tk
- TITLE_FONT = ("Helvetica", 18, "bold")
- class SampleApp(tk.Tk):
- def __init__(self, *args, **kwargs):
- tk.Tk.__init__(self, *args, **kwargs)
- container = tk.Frame(self)
- self.title(" Allocation")
- width, height = self.winfo_screenwidth(), self.winfo_screenheight()
- self.geometry('%dx%d+0+0' % (width,height))
- self.state('zoomed')
- 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, c):
- frame = self.frames[c]
- frame.tkraise()
- class StartPage(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- self.controller = controller
- label = tk.Label(self, text="This is the start page", font=TITLE_FONT)
- label.place(x=0,y=0,width=592,height=44)
- frame1 = tk.Frame(self)
- tk.Label(frame1, bd=5,bg="black",text=" Enter text : ",font=("Helvetica", 14),fg="light green",width=21).pack(side=tk.LEFT)
- self.emp=tk.Entry(frame1, bd =5,font=("Times New Roman", 14),width=25)
- self.emp.pack(side=tk.LEFT)
- frame1.place(x=400,y=160)
- button1 = tk.Button(self, text="Go to Page One",
- command=lambda: self.go_to_page_one())
- button2 = tk.Button(self, text="Go to Page two",
- command=lambda: controller.show_frame(PageTwo))
- button3 = tk.Button(self, text="Exit",
- command=self.quit)
- button1.place(x=100,y=406,width=200,height=44)
- button2.place(x=300,y=406,width=200,height=44)
- button3.place(x=500,y=406,width=80,height=44)
- def go_to_page_one(self):
- self.controller.SomeVar = self.emp.get()
- self.controller.frames[PageOne].correct_label()
- self.controller.show_frame(PageOne)
- class PageOne(tk.Frame):
- def __init__(self, parent, controller):
- self.controller = controller
- tk.Frame.__init__(self, parent)
- self.label = tk.Label(self, text="This is page one", font=TITLE_FONT)
- self.label.place(x=0,y=0,width=592,height=44)
- button1 = tk.Button(self, text="Go to Start Page",
- command=lambda: controller.show_frame(StartPage))
- #button2 = tk.Button(self, text="Go to Page two",
- # command=lambda: controller.show_frame(PageTwo))
- button3 = tk.Button(self, text="Exit",
- command=self.quit)
- button1.place(x=100,y=406,width=200,height=44)
- button3.place(x=300,y=406,width=200,height=44)
- def correct_label(self):
- self.label.config(text=self.controller.SomeVar)
- class PageTwo(tk.Frame):
- def __init__(self, parent, controller):
- tk.Frame.__init__(self, parent)
- label = tk.Label(self, text="This is page two", font=TITLE_FONT)
- label.place(x=0,y=0,width=592,height=44)
- button1 = tk.Button(self, text="Go to Start Page",
- command=lambda: controller.show_frame(StartPage))
- #button2 = tk.Button(self, text="Go to Page two",
- # command=lambda: controller.show_frame(PageTwo))
- button3 = tk.Button(self, text="Exit",
- command=self.quit)
- button1.place(x=100,y=406,width=200,height=44)
- button3.place(x=300,y=406,width=200,height=44)
- if __name__ == "__main__":
- app = SampleApp()
- app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement