← QCE Digital Solutions Unit 1

Event triggers changing the user interface

A handler runs when an event happens and can call config() to change the interface, such as updating a label's text to give the user feedback.

Understanding Event triggers changing the user interface in QCE Digital Solutions Unit 1

What it does: The handler runs on a keyboard event and uses config() to change the label text to the key's name. Updating a label tells the user that their click or key press was received and what happened. config() changes the widget it is called on. Here that is msg, not the button. You cannot join a string and an integer with +. Converting the score with str() avoids a TypeError. Text given to config() is a string, so it must be wrapped in quotes.

Common mistakes: The option that sets a label's text is text, not txt. It should be label.config(text='Done'), otherwise tkinter raises an error and the label never updates. Setting an attribute called text does not change what the label shows on screen. Use label.config(text=key) so the handler updates the interface.

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 158–380) and word search (Modules 82–380).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line changes the text of a tkinter label called status when a handler runs?
status.text = config('Saved')status.config(text='Saved')
Matches
label.config(text=Done)
↓
The text value is missing quotes, so Python treats Done as a variable name and gives a NameError. It should be text='Done'.
Applying
Meanings
Term
label.config(text='Done')
Meaning
A handler runs when an event happens and can call config() to change the interface, such as updating a label's text to give the user feedback.
Practice
import tkinter as tk
Testing
Gaps
label.(text='Done')
Check Answer
Spots
1def done():
2 label.config(txt='Done')

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

The 'Hedgehog' badge — First Steps, 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 changes the text of a tkinter label called status when a handler runs?
A. status.text = config('Saved')
B. status.config(text='Saved') ✓
config() is a method of the widget. You pass the property to change, such as text='Saved', as a keyword argument.
2. What is the main reason a handler calls label.config(text=...)?
A. To give the user feedback after an event ✓
B. To create a new window each time
Updating a label tells the user that their click or key press was received and what happened.
3. A button's handler contains this line: msg.config(fg='red'). What happens when the button is clicked?
A. The colour of the text in msg changes to red ✓
B. The button itself turns red
config() changes the widget it is called on. Here that is msg, not the button.
4. Which handler gives feedback when a key is pressed?
A. def on_key(event): label.config(event.keysym)
B. def on_key(event): label.config(text=event.keysym) ✓
config() needs the keyword text= to say which property to change. Without it, tkinter raises an error.
5. True or false: the label on screen updates by itself when you change a variable, without calling config().
A. False. You must call config() in the handler ✓
B. True. The label always follows the variable
A plain variable is not linked to the label. The handler has to call label.config(text=...) to change what the user sees.

Match the Pairs

label.config(text='Saved') → Changes the text shown on a label so the user sees feedback after an event
button.config(bg='green') → Changes the background colour of a widget when the handler runs
A key press handler updates a label to show which key the user pressed → def on_key(event): label.config(text=event.keysym)
A mouse click handler changes a label so the user knows the click was detected → def on_click(event): label.config(text='Clicked!')
label.config(text=Done) → The text value is missing quotes, so Python treats Done as a variable name and gives a NameError. It should be text='Done'.
label.config('Done') → config() needs the option name text= before the value. It should be label.config(text='Done').

Key Term

label.config(text='Done')
A handler runs when an event happens and can call config() to change the interface, such as updating a label's text to give the user feedback.

Fill in the Blanks

1. label.config(text='Done')
Hint: Type the method that changes a widget's settings after it has been created.
2. label.config(text='Saved')
Hint: Type the option name that sets the words a label displays.
3. def warn(): label.config(fg='red') button = tk.Button(root, command=warn)
Hint: Type the short option name for a widget's foreground (text) colour.
4. def show(event): label.config(text='Key pressed') root.bind('<Key>', show)
Hint: Type the method that connects a keyboard event to its handler function.
5. def show(event): label.config(text='Mouse clicked') label.bind('<Button-1>', show)
Hint: Type the parameter name that receives the details of the mouse event.

Spot the Error

Question 1
A def done():
B label.config(txt='Done')
C btn = tk.Button(command=done)
Line B — The option that sets a label's text is text, not txt. It should be label.config(text='Done'), otherwise tkinter raises an error and the label never updates.
Question 2
A def on_key(event):
B key = event.keysym
C label.text = key
D root.bind('<Key>', on_key)
Line C — Setting an attribute called text does not change what the label shows on screen. Use label.config(text=key) so the handler updates the interface.
Question 3
A def hover(event):
B btn.config(bg='yellow')
C msg.config(text='Hover')
D btn.bind('<Enter>', hover())
Line D — hover() calls the handler straight away instead of passing it to bind. It should be btn.bind('<Enter>', hover) so it only runs when the mouse enters the button.
Question 4
A def leave(event):
B btn.config(bg='white')
C msg.config(text='Bye')
D btn.bind(leave, '<Leave>')
Line D — The arguments to bind are in the wrong order. The event name comes first, then the handler: btn.bind('<Leave>', leave).
Question 5
A def on_key():
B label.config(text='Key!')
C root.bind('<Key>', on_key)
Line A — bind() passes an event object to the handler, so the handler needs a parameter. It should be def on_key(event):.

Student with a class code? Join your class →