here2share

# tk_page_flip_frames.py

Sep 14th, 2021 (edited)
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. # tk_page_flip_frames.py
  2.  
  3. from tkinter import *
  4.  
  5. root = Tk()
  6. root.title('tk Page Flip Frames')
  7. root.geometry('500x250+300+300')
  8.  
  9. # Position frame
  10. frame = LabelFrame(root, text='Press Button To Select A Frame', padx=25, pady=25)
  11. frame.pack(padx=10, pady=50)
  12.  
  13. # What do the buttons do
  14. def xyz(frame):
  15.     frame.destroy()
  16.     frame = LabelFrame(root, text='Frame XYZ', padx=25, pady=25)
  17.     frame.pack(padx=10, pady=50)
  18.     theFrame = Label(frame, text='XYZ Has Been Chosen')
  19.     theFrame.grid(row=0, column=0, columnspan=2)
  20.  
  21.     back(frame)
  22.  
  23. def abc(frame):
  24.     frame.destroy()
  25.     frame = LabelFrame(root, text='Frame ABC', padx=25, pady=25)
  26.     frame.pack(padx=10, pady=50)
  27.     theFrame = Label(frame, text='ABC Has Been Chosen')
  28.     theFrame.grid(row=0, column=0, columnspan=2)
  29.    
  30.     back(frame)
  31.    
  32. def back(frame):
  33.     # Option to go back
  34.     homepage = Button(frame, text='BACK', command=lambda:mainframe(frame))
  35.     homepage.grid(row=1, column=0, columnspan=2, pady=10)
  36.  
  37. def mainframe(frame):
  38.     frame.destroy()
  39.     frame = LabelFrame(root, text='The Main Frame', padx=25, pady=25)
  40.     frame.pack(padx=10, pady=50)
  41.  
  42.     # Create the buttons and put them in the frame
  43.     b = Button(frame, text="XYZ", fg='red', command=lambda:xyz(frame))
  44.     b2 = Button(frame, text='ABC', fg='green', command=lambda:abc(frame))
  45.  
  46.     b.grid(row=0, column=0, padx=3)
  47.     b2.grid(row=0, column=1, padx=3)
  48.  
  49. mainframe(frame)
  50. root.mainloop()
  51.  
Add Comment
Please, Sign In to add comment