Bird
0
0
Raspberry Piprogramming~10 mins

Tkinter GUI for sensor dashboard in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create the main window for the sensor dashboard.

Raspberry Pi
import tkinter as tk

root = tk.[1]()
root.title("Sensor Dashboard")
root.geometry("400x300")
root.mainloop()
Drag options to blanks, or click blank then click option'
AWindow
BCanvas
CFrame
DTk
Attempts:
3 left
💡 Hint
Common Mistakes
Using tk.Window() instead of tk.Tk()
Trying to create a Frame as the main window
Using tk.Canvas() as the main window
2fill in blank
medium

Complete the code to add a label widget that shows the sensor name.

Raspberry Pi
label = tk.Label(root, text=[1], font=("Arial", 16))
label.pack(pady=10)
Drag options to blanks, or click blank then click option'
ATemperature Sensor
Blabel_text
C"Temperature Sensor"
Dsensor_name
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the text string
Passing a variable name without defining it
Using single quotes inconsistently
3fill in blank
hard

Fix the error in the code to update the sensor value label dynamically.

Raspberry Pi
def update_value():
    sensor_value = 25  # example sensor reading
    value_label.[1](text=f"Value: {sensor_value} °C")

value_label = tk.Label(root, text="Value: -- °C", font=("Arial", 14))
value_label.pack()

root.after(1000, update_value)
Drag options to blanks, or click blank then click option'
Aconfig
Bconfigure
Cupdate_text
Dset_text
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like update_text or set_text
Using config instead of configure (both work but configure is preferred here)
Trying to assign text directly
4fill in blank
hard

Fill both blanks to create a button that starts sensor data updates and packs it with padding.

Raspberry Pi
start_button = tk.Button(root, text=[1], command=[2])
start_button.pack(pady=20)
Drag options to blanks, or click blank then click option'
A"Start"
Bupdate_value
C"Stop"
Droot.quit
Attempts:
3 left
💡 Hint
Common Mistakes
Using function call with parentheses in command
Not using quotes around the button text
Using wrong function names
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps sensor names to their latest values if the value is above 20.

Raspberry Pi
sensor_data = { [1]: [2] for [1], [2] in [3] if [2] > 20 }
Drag options to blanks, or click blank then click option'
Asensor
Bvalue
Csensors.items()
Dsensor_value
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not unpacking items() correctly
Using sensor_value instead of value