#pack_sample.py # Use a StringVar to create a changeable label from Tkinter import * # Hold onto a global reference for the root window root = None count = 0 # Click counter def addButton(root, sideToPack): global count name = "Button "+ str(count) +" "+sideToPack button = Button(root, text=name) button.pack(side=sideToPack) count +=1 def addLabel(parent, sideToPack=TOP): global count l = Label(parent, text="Label "+ str(count)) l.pack(side=sideToPack) count+=1 def main(): global root root = Tk() # Create the root (base) window where all widgets go frame0 = Frame(root) # Holds Frame 1 and 2 frame1 = Frame(frame0) addButton(frame1, TOP) addButton(frame1, TOP) addButton(frame1, TOP) addButton(frame1, TOP) addButton(frame1, TOP) frame1.pack(side=LEFT) frame2 = Frame(frame0) addButton(frame2, TOP) addButton(frame2, TOP) addButton(frame2, TOP) frame2.pack(side=LEFT) # Top Frame frame3 = Frame(root) addLabel(frame3) # Bottom Frame frame4 = Frame(root) addLabel(frame4) frame3.pack(side=TOP) frame0.pack(side=TOP) frame4.pack(side=TOP) root.mainloop() # Start the event loop main()