Bird
0
0
Raspberry Piprogramming~20 mins

Tkinter GUI for sensor dashboard in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tkinter Sensor Dashboard Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
visualization
intermediate
2:00remaining
Display Real-Time Temperature on Tkinter Label

You want to show the current temperature reading from a sensor on a Tkinter label that updates every second. Which code snippet correctly updates the label text with the latest temperature?

Raspberry Pi
import tkinter as tk
import random

def get_temperature():
    return random.uniform(20.0, 30.0)

root = tk.Tk()
label = tk.Label(root, text="Temperature: -- °C")
label.pack()

# Which update function is correct?

# Option A
# def update():
#     temp = get_temperature()
#     label.config(text="Temperature: " + str(temp) + " °C")
#     root.after(1000, update)

# Option B
# def update():
#     temp = get_temperature()
#     label['text'] = "Temperature: " + temp + " °C"
#     root.after(1000, update)

# Option C
# def update():
#     temp = get_temperature()
#     label.config(text=f"Temperature: {temp:.1f} °C")
#     root.after(1000, update)

# Option D
# def update():
#     temp = get_temperature()
#     label.text = f"Temperature: {temp:.1f} °C"
#     root.after(1000, update)

update()
root.mainloop()
A
def update():
    temp = get_temperature()
    label.config(text=f"Temperature: {temp:.1f} °C")
    root.after(1000, update)
B
def update():
    temp = get_temperature()
    label['text'] = "Temperature: " + temp + " °C"
    root.after(1000, update)
C
def update():
    temp = get_temperature()
    label.config(text="Temperature: " + str(temp) + " °C")
    root.after(1000, update)
D
def update():
    temp = get_temperature()
    label.text = f"Temperature: {temp:.1f} °C"
    root.after(1000, update)
Attempts:
2 left
💡 Hint

Remember to convert numbers to strings when concatenating, and use the correct method to update label text.

data_modeling
intermediate
1:30remaining
Organizing Sensor Data for Dashboard Display

You have multiple sensors sending temperature and humidity data. Which data structure best organizes this data for easy access and display in a Tkinter dashboard?

AA single string concatenating all sensor data separated by commas.
BA dictionary with sensor IDs as keys and tuples (temperature, humidity) as values.
CTwo separate lists: one for temperatures and one for humidities, indexed by sensor ID.
DA list of dictionaries, each dictionary with keys 'sensor_id', 'temperature', and 'humidity'.
Attempts:
2 left
💡 Hint

Think about quick lookup by sensor ID and grouping related data together.

dax_lod_result
advanced
2:30remaining
Calculate Average Temperature per Sensor Using DAX

You have a table 'SensorReadings' with columns 'SensorID', 'Timestamp', and 'Temperature'. Which DAX measure calculates the average temperature per sensor correctly?

Raspberry Pi
AverageTempPerSensor = CALCULATE(AVERAGE(SensorReadings[Temperature]), ALLEXCEPT(SensorReadings, SensorReadings[SensorID]))
AAverageTempPerSensor = CALCULATE(AVERAGE(SensorReadings[Temperature]), ALL(SensorReadings))
BAverageTempPerSensor = AVERAGE(SensorReadings[Temperature])
CAverageTempPerSensor = CALCULATE(AVERAGE(SensorReadings[Temperature]), ALLEXCEPT(SensorReadings, SensorReadings[SensorID]))
DAverageTempPerSensor = SUM(SensorReadings[Temperature]) / COUNT(SensorReadings[SensorID])
Attempts:
2 left
💡 Hint

Use ALLEXCEPT to keep the filter on SensorID while removing others.

🔧 Debug
advanced
1:30remaining
Fix Tkinter Button Not Responding to Click

You created a Tkinter button to refresh sensor data, but clicking it does nothing. What is the most likely cause?

Raspberry Pi
import tkinter as tk

def refresh():
    print("Refreshing data")

root = tk.Tk()
button = tk.Button(root, text="Refresh", command=refresh())
button.pack()
root.mainloop()
AThe command parameter should be set to refresh without parentheses: command=refresh
BThe button text is incorrect; it should be 'Refresh Data' to work.
CThe refresh function must return True to trigger the button.
DThe button needs to be packed after mainloop() to respond.
Attempts:
2 left
💡 Hint

Check how the command parameter is assigned in Tkinter buttons.

🎯 Scenario
expert
3:00remaining
Designing a Responsive Tkinter Dashboard for Multiple Sensors

You must design a Tkinter dashboard that shows live readings from 10 sensors. Each sensor has temperature and humidity labels that update every second. What is the best approach to ensure the GUI remains responsive and updates correctly?

AUpdate all sensor labels only when the user clicks a refresh button.
BCreate 10 separate threads, each updating one sensor's labels independently every second.
CUse a while True loop inside the main thread to update all labels continuously without delay.
DUse a single update function that loops through all sensors, updates their labels, and schedules itself with root.after(1000).
Attempts:
2 left
💡 Hint

Tkinter is not thread-safe; consider how to update UI without freezing it.