Python Forum
Raspberry pi Sensehat auto update
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry pi Sensehat auto update
#4
from datetime import datetime
import tkinter as tk

running = False

def update_time():
    """Update the time display"""
    if running:
        time_display.set(datetime.now().strftime('%H:%M:%S'))
        root.after(1000, update_time)  # Scedule myself to run again

def start_stop():
    """Start/stop updating the time display"""
    global running
    running = not running
    if running:
        update_time()

root = tk.Tk()
time_display = tk.StringVar()
tk.Label(root, textvariable=time_display, width=8).pack(padx=10, pady=10)
tk.Button(root, text='Start/Stop', command=start_stop).pack(padx=10, pady=10)
root.mainloop()
This doesn't do anything in you program.
#Set Globals
global pitchLabel
global rollLabel
global yowLabel
Using the "global" keyword only makes sense inside a function. It tells Python to not create a local variable when doing variable assignment.
global_variable=0
def uses_local_variable(value):
    global_variable = value

def uses_global_variable(value):
    global global_variable
    global_variable = value

print(global_variable)
uses_local_variable(5)
print(global_variable)
uses_global_variable(10)
print(global_variable)
Output:
0 0 10
Reply


Messages In This Thread
Raspberry pi Sensehat auto update - by mrbronz61 - Apr-08-2021, 06:00 PM
RE: Raspberry pi Sensehat auto update - by deanhystad - Apr-09-2021, 04:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 821 Dec-16-2020, 05:26 AM
Last Post: Vokofe

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020