Bird
0
0

Given this code snippet, what will be the output on the label after 3 seconds?

medium📝 Predict Output Q4 of 15
Raspberry Pi - Display and Output
Given this code snippet, what will be the output on the label after 3 seconds?
import tkinter as tk
import time

def update_label():
    value = int(time.time()) % 100
    label.config(text=str(value))
    root.after(1000, update_label)

root = tk.Tk()
label = tk.Label(root, text="0")
label.pack()
update_label()
root.mainloop()
AThe label shows the full current time in seconds
BThe label shows '0' and never updates
CThe label updates every second showing the last two digits of current time in seconds
DThe program crashes due to syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand update_label function

    It calculates current time in seconds modulo 100, converts to string, updates label text, then schedules itself after 1 second.
  2. Step 2: Predict label behavior after 3 seconds

    Label updates every second showing last two digits of current time seconds continuously.
  3. Final Answer:

    The label updates every second showing the last two digits of current time in seconds -> Option C
  4. Quick Check:

    Label updates every second = The label updates every second showing the last two digits of current time in seconds [OK]
Quick Trick: after() schedules repeated updates without freezing GUI [OK]
Common Mistakes:
MISTAKES
  • Thinking label never updates
  • Confusing modulo operation
  • Assuming syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes