← VCE Software Development U3O1

Placing controls with grid() and pack()

Places a control in a table-like layout at the given row and column. pack() instead stacks controls in order. Never mix grid and pack in one window.

Understanding Placing controls with grid() and pack() in VCE Software Development U3O1

What it does: padx adds horizontal padding (left and right) around the control, while pady adds vertical padding (top and bottom). columnspan=2 makes the control take up two columns, which is useful for headings that sit above two columns of controls. Rows and columns both start at 0, so the first row is row=0 and the second column is column=1. pack() needs no row or column. It simply stacks each control after the previous one. Row and column belong to grid(). Controls on the same row share the same row number but use different column numbers. The correct option name is columnspan. colspan is HTML, not tkinter, and causes an error.

Common mistakes: The grid() call is missing its closing bracket. It should be lb.grid(row=0, column=1) so the label is placed in row 0, column 1. grid() and pack() must not be mixed in one window. The other control uses pack(), so this line should be a.pack().

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 125–141) and word search (Modules 114–141).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line places a Label in the first row, second column of a grid layout?
lbl.grid(row=0, column=1)lbl.grid(row=1, column=0)
Matches
name_label.grid(row=0, column=0) name_entry.pack()
↓
grid() and pack() are mixed in the same window. This causes tkinter to fail or freeze. Use grid() for every control, e.g. name_entry.grid(row=0, column=1).
Applying
Meanings
Term
control.grid(row=0, column=1)
Meaning
Places a control in a table-like layout at the given row and column. pack() instead stacks controls in order. Never mix grid and pack in one window.
Practice
import tkinter as tk
Testing
Gaps
lblName.grid(=0, column=0)
Check Answer
Spots
3lb = tk.Label(win, text='Hi')
4lb.grid(row=0, column=1

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Tree Frog' badge — Leap of Logic, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line places a Label in the first row, second column of a grid layout?
A. lbl.grid(row=0, column=1) ✓
B. lbl.grid(row=1, column=0)
Rows and columns both start at 0, so the first row is row=0 and the second column is column=1.
2. Which statement about pack() is correct?
A. pack() needs a row and column number for every control
B. pack() stacks controls in the order they are packed ✓
pack() needs no row or column. It simply stacks each control after the previous one. Row and column belong to grid().
3. You want a Label and an Entry side by side on one row. Which is correct?
A. lbl.grid(row=0, column=0) and txt.grid(row=0, column=1) ✓
B. lbl.grid(row=0, column=0) and txt.grid(row=1, column=0)
Controls on the same row share the same row number but use different column numbers.
4. Which line adds 10 pixels of space to the left and right of a control?
A. btn.grid(row=2, column=0, pady=10)
B. btn.grid(row=2, column=0, padx=10) ✓
padx adds horizontal space (left and right). pady adds vertical space (above and below).
5. Which line makes a Button stretch across two columns?
A. btn.grid(row=3, column=0, columnspan=2) ✓
B. btn.grid(row=3, column=0, colspan=2)
The correct option name is columnspan. colspan is HTML, not tkinter, and causes an error.

Match the Pairs

label.grid(row=0, column=1) → Places the label in the first row (row 0) and second column (column 1) of the window's table-like layout.
entry.pack() → Stacks the entry control in the window below the controls that were packed before it.
Add 10 pixels of space on the left and right of a control in a grid layout → button.grid(row=2, column=0, padx=10)
Make a heading label stretch across two columns of the grid → title.grid(row=0, column=0, columnspan=2)
name_label.grid(row=0, column=0) name_entry.pack() → grid() and pack() are mixed in the same window. This causes tkinter to fail or freeze. Use grid() for every control, e.g. name_entry.grid(row=0, column=1).
submit_button.grid(row=1, col=0) → The argument name is wrong. grid() uses column, not col. It should be submit_button.grid(row=1, column=0).

Key Term

control.grid(row=0, column=1)
Places a control in a table-like layout at the given row and column. pack() instead stacks controls in order. Never mix grid and pack in one window.

Fill in the Blanks

1. lblName.grid(row=0, column=0)
Hint: Type the argument name that picks which horizontal line of the table the control sits in.
2. entName.grid(row=0, column=1)
Hint: Type the argument name that picks which vertical stripe of the table the control sits in.
3. btnSave.grid(row=2, column=0, columnspan=2)
Hint: Type the argument name that stretches a control across several table stripes.
4. lblName.grid(row=1, column=0, padx=8)
Hint: Type the argument name that adds horizontal spacing around a control.
5. btnOk.pack(pady=5)
Hint: Type the method that stacks controls one after another in the order they are added.

Spot the Error

Question 1
A import tkinter as tk
B win = tk.Tk()
C lb = tk.Label(win, text='Hi')
D lb.grid(row=0, column=1
E win.mainloop()
Line D — The grid() call is missing its closing bracket. It should be lb.grid(row=0, column=1) so the label is placed in row 0, column 1.
Question 2
A a = tk.Label(win, text='A')
B a.grid(row=0, column=0)
C b = tk.Label(win, text='B')
D b.pack()
Line B — grid() and pack() must not be mixed in one window. The other control uses pack(), so this line should be a.pack().
Question 3
A b = tk.Button(win, text='Go')
B b.pack(padding=5)
C c = tk.Button(win, text='End')
D c.pack(padx=5, pady=5)
Line B — There is no padding option for pack(). Spacing around a control uses padx and pady, so it should be b.pack(padx=5, pady=5).
Question 4
A t = tk.Label(win, text='Menu')
B e = tk.Entry(win)
C e.grid(row=1, column=0)
D t.grid(row=0, colspan=2)
E win.mainloop()
Line D — colspan is the HTML name. In tkinter the option is columnspan, so it should be t.grid(row=0, columnspan=2).
Question 5
A lb = tk.Label(win, text='Age')
B lb.grid(0, 0)
C en = tk.Entry(win)
D en.grid(row=0, column=1)
Line B — grid() needs the keyword arguments row= and column=. Plain numbers do not work, so it should be lb.grid(row=0, column=0).

Student with a class code? Join your class →