Advertisement
thestarchyninja

Python Programming

Jan 30th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import Tkinter as tk
  2.  
  3. class ProgramScreen(tk.Tk):
  4. def __init__(self,*args,**kwargs):
  5. tk.Tk.__init__(self,*args,**kwargs)
  6. container=tk.Frame(self)
  7. container.pack(expand=True, fill="both")
  8. container.grid_rowconfigure(0,weight=1)
  9. self.frames={}
  10. self.foo=tk.StringVar()
  11. for F in (Screen1,Screen2):
  12. page_name=F.__name__
  13. frame=F(parent=container,controller=self)
  14. self.frames[page_name]=frame
  15. frame.grid(row=0,column=0,sticky="nsew")
  16. self.show_frame("Screen1")
  17. def show_frame(self,page_name):
  18. frame=self.frames[page_name]
  19. frame.tkraise()
  20. def add(self,a,b):
  21. c=str(int(a)+int(b))
  22. self.foo.set(c)
  23. self.show_frame("Screen2")
  24. class Screen1(tk.Frame):
  25. def __init__(self,parent,controller):
  26. tk.Frame.__init__(self,parent)
  27. self.controller=controller
  28. self.pack(fill="x",expand=1)
  29. entry1=tk.Entry(self)
  30. entry1.pack()
  31. entry2=tk.Entry(self)
  32. entry2.pack()
  33. button1=tk.Button(self,text="Lorem",command=lambda: controller.add(entry1.get(),entry2.get()))
  34. button1.pack()
  35. class Screen2(tk.Frame):
  36. def __init__(self,parent,controller):
  37. tk.Frame.__init__(self,parent)
  38. self.controller=controller
  39. self.pack(fill="x",expand=1)
  40. label1=tk.Label(self,textvariable=controller.foo.get())
  41. label1.pack()
  42.  
  43. if __name__ == "__main__":
  44. app = ProgramScreen()
  45. app.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement