[source code] Python GUI with Tkinter - 4 & 5 - Grid Layout

+1 Bucky Roberts · September 11, 2014
from tkinter import *

root = Tk()

label_1 = Label(root, text="Name")
label_2 = Label(root, text="Password")
entry_1 = Entry(root)
entry_2 = Entry(root)

# widgets centered by default, sticky option to change
label_1.grid(row=0, sticky=E)
label_2.grid(row=1, sticky=E)

entry_1.grid(row=0, column=1)
entry_2.grid(row=1, column=1)

# widgets can take up more than one cell with columnspan and rowspan
c = Checkbutton(root, text="Keep me logged in")
c.grid(columnspan=2)

root.mainloop()

Post a Reply

Replies

Oldest  Newest  Rating
0 Wayne [Im That Damn Good] Leyden · September 13, 2014
Can you use pack and grid in the same frame?
If so, what would show first, would it depend on the order of the code?
+1 Bucky Roberts · September 13, 2014
Nope, never use grid and pack together. It causes major issues in Tkinter. 
  • 1

Python

107,257 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator