← VCE Software Development U3O1

Creating a tkinter window

Creates the main tkinter window after import tkinter as tk. Call root.mainloop() at the end to show the window and wait for events like clicks.

Understanding Creating a tkinter window in VCE Software Development U3O1

What it does: root.title() takes a string and displays it in the title bar of the window created with tk.Tk(). tk.Tk() creates the main window object. There is no tk.window() function in tkinter. The module is called tkinter. 'as tk' gives it the short name tk, so tk.Tk() works. mainloop() starts waiting for events and runs until the window is closed. root must exist first, and any setup code placed after mainloop() would not run until the window closes. The title() method sets the title bar text. tkinter has no name() method for this. geometry() takes ONE string in the form 'widthxheight', such as '400x300'. It does not take two separate numbers.

Common mistakes: The window class is Tk with a capital T. tk.tk() causes an AttributeError. It should be root = tk.Tk(). Python is case-sensitive and the method name is all lowercase. root.Title does not exist. It should be root.title("Quiz").

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 114–124) 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 creates the main tkinter window?
root = tk.window()root = tk.Tk()
Matches
import tkinter as tk root = tk.Tk() root.mainloop() root.title("Quiz")
↓
root.mainloop() is placed before root.title(), so the title line only runs after the window is closed. mainloop() must be the last line.
Applying
Meanings
Term
root = tk.Tk()
Meaning
Creates the main tkinter window after import tkinter as tk. Call root.mainloop() at the end to show the window and wait for events like clicks.
Practice
import tkinter as tk
Testing
Gaps
tkinter as tk
Check Answer
Spots
1import tkinter as tk
2root = tk.tk()

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

The 'Sperm Whale' badge — Deep Sea Champion, 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 creates the main tkinter window?
A. root = tk.Tk() ✓
B. root = tk.window()
tk.Tk() creates the main window object. There is no tk.window() function in tkinter.
2. Which import lets you write tk.Tk() in your code?
A. import tkinter as tk ✓
B. import tk as tkinter
The module is called tkinter. 'as tk' gives it the short name tk, so tk.Tk() works.
3. Where should root.mainloop() go in a simple tkinter program?
A. At the start, before root = tk.Tk()
B. At the end, after the window is set up ✓
mainloop() starts waiting for events and runs until the window is closed. root must exist first, and any setup code placed after mainloop() would not run until the window closes.
4. What does root.mainloop() do?
A. Repeats the program code ten times
B. Shows the window and waits for events like clicks ✓
mainloop() keeps the window open and listens for events such as clicks and key presses until the window is closed.
5. Which line sets the text in the window's title bar to 'My App'?
A. root.title('My App') ✓
B. root.name('My App')
The title() method sets the title bar text. tkinter has no name() method for this.

Match the Pairs

root = tk.Tk() → Creates the main tkinter window and stores it in the variable root
root.mainloop() → Shows the window and waits for events such as clicks and key presses
Set the text shown in the title bar of the window → root.title("My App")
Set the window size to 400 pixels wide and 300 pixels high → root.geometry("400x300")
import tkinter as tk root = tk.Tk() root.mainloop() root.title("Quiz") → root.mainloop() is placed before root.title(), so the title line only runs after the window is closed. mainloop() must be the last line.
import tkinter as tk root = tk.Tk root.mainloop() → tk.Tk is missing its brackets, so no window is created. It should be tk.Tk().

Key Term

root = tk.Tk()
Creates the main tkinter window after import tkinter as tk. Call root.mainloop() at the end to show the window and wait for events like clicks.

Fill in the Blanks

1. import tkinter as tk root = tk.Tk() root.mainloop()
Hint: Type the keyword that loads the tkinter module into your program
2. import tkinter as tk root = tk.Tk() root.mainloop()
Hint: Type the tkinter class name that creates the main window
3. import tkinter as tk root = tk.Tk() root.mainloop()
Hint: Type the method that shows the window and waits for events like clicks
4. root = tk.Tk() root.title("My App") root.mainloop()
Hint: Type the method that sets the text shown in the window's title bar
5. root = tk.Tk() root.geometry("400x300") root.mainloop()
Hint: Type the method that sets the window's width and height

Spot the Error

Question 1
A import tkinter as tk
B root = tk.tk()
C root.title("My App")
D root.mainloop()
Line B — The window class is Tk with a capital T. tk.tk() causes an AttributeError. It should be root = tk.Tk().
Question 2
A import tkinter as tk
B root = tk.Tk()
C root.Title("Quiz")
D root.mainloop()
Line C — Python is case-sensitive and the method name is all lowercase. root.Title does not exist. It should be root.title("Quiz").
Question 3
A import tkinter as tk
B root = tk.Tk()
C root.geometry("400x300")
D root.mainloop
Line D — Without brackets, mainloop is not called, so the window closes straight away. It should be root.mainloop().
Question 4
A import tkinter as tk
B root = tk.Tk()
C root.geometry("400,300")
D root.mainloop()
Line C — The size string must be width x height with a lowercase x between the numbers, not a comma. It should be root.geometry("400x300").
Question 5
A import Tkinter as tk
B root = tk.Tk()
C root.title("Game")
D root.mainloop()
Line A — In Python 3 the module name is all lowercase. Tkinter with a capital T causes a ModuleNotFoundError. It should be import tkinter as tk.

Student with a class code? Join your class →