[source code] Python GUI with Tkinter - 2 - Organizing your Layout

+1 Bucky Roberts · September 11, 2014

from tkinter import *

root = Tk()

# Frame is a rectangular area that can contain other widgets
topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM)

button1 = Button(topFrame, text="Button 1", fg="red")
button2 = Button(topFrame, text="Button 2", fg="blue")
button3 = Button(topFrame, text="Button 3", fg="green")
button4 = Button(bottomFrame, text="Button 4", fg="purple")

# These buttons will be on top
button1.pack(side=LEFT)  # place as far left as possible
button2.pack(side=LEFT)
button3.pack(side=LEFT)
# Button 4 is on the bottom
button4.pack(side=BOTTOM)

root.mainloop()

Post a Reply

Replies

Oldest  Newest  Rating
0 Jörg Bummer · November 20, 2014
in above example you can make the frames visible when you stretch the root window
0 Jörg Bummer · November 20, 2014

from tkinter import *

root = Tk()

# Frame is a rectangular area that can contain other widgets
topFrame = Frame(root, bg="red")
topFrame.pack(side=TOP, fill=X)
bottomFrame = Frame(root, bg="blue")
bottomFrame.pack(side=BOTTOM, fill=X)

button1 = Button(topFrame, text="Button 1", fg="red")
button2 = Button(topFrame, text="Button 2", fg="blue")
button3 = Button(topFrame, text="Button 3", fg="green")
button4 = Button(bottomFrame, text="Button 4", fg="purple")

# These buttons will be on top
button1.pack(side=LEFT)  # place as far left as possible
button2.pack(side=LEFT)
button3.pack(side=LEFT)
# Button 4 is on the bottom
button4.pack(side=BOTTOM)

root.mainloop()
  • 1

Python

107,113 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator