Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_frame_ratio_divided.py
- import Tkinter as Tk
- # Main window
- master = Tk.Tk()
- master.geometry("200x60+20+20")
- # Callback event that resizes the main components
- def resize_it(event):
- global master # Main Window
- global a # Red Frame
- global b # Blue Frame
- #Reconfigure the main window's and frames' dimensions
- a.configure(width=event.width/2, height=event.height/2)
- b.configure(width=event.width/2, height=event.height/2)
- master.configure(width=event.width, height=event.height)
- #Create a red (first) Frame
- a = Tk.Frame(master, bg='red')
- a.pack(side='left', expand=True, fill=Tk.BOTH)
- # Draw a button on frame a
- a1 = Tk.Button(a, text='Demo Button')
- a1.grid(row=0, column=0)
- # Disable geometry propagation
- a.grid_propagate(0)
- #Create a blue (second) Frame
- b = Tk.Frame(master, bg='blue')
- b.pack(side='left', expand=True, fill=Tk.BOTH)
- # Draw a label on frame b
- l1 = Tk.Label(b, text='Label Demo '*10)
- l1.grid(row=0, column=0)
- # Disable geometry propagation on frame b
- # Note: always after adding ALL the desired widgets to b. Same note for frame b
- b.grid_propagate(0)
- master.bind('<Configure>', resize_it)
- #Start program
- master.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement