Bird
0
0

Identify the issue in this Tkinter code that attempts to update a label every second:

medium📝 Debug Q7 of 15
Raspberry Pi - Display and Output
Identify the issue in this Tkinter code that attempts to update a label every second:
import tkinter as tk
root = tk.Tk()
label = tk.Label(root, text="0")
label.pack()

def update():
    label.config(text="1")
    update()

update()
root.mainloop()
ALabel text is not updated because config method is incorrect
BThe update function calls itself recursively without delay, freezing the GUI
Croot.mainloop() is missing, so GUI never starts
DLabel widget is not packed, so it won't display
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the update function

    The function calls itself recursively without any delay or event scheduling.
  2. Step 2: Effect on GUI

    This causes the program to enter an infinite recursive loop, freezing the GUI and preventing mainloop from running properly.
  3. Final Answer:

    The update function calls itself recursively without delay, freezing the GUI -> Option B
  4. Quick Check:

    Recursive calls without delay block event loop [OK]
Quick Trick: Avoid infinite recursion; use after() for scheduling [OK]
Common Mistakes:
MISTAKES
  • Forgetting to use root.after() for timed updates
  • Calling update() recursively without pause
  • Misunderstanding mainloop's role in GUI responsiveness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes