Python Forum
Raspberry pi Sensehat auto update
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry pi Sensehat auto update
#5
(Apr-09-2021, 04:26 PM)deanhystad Wrote:
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

Thank you but as you can see from my reply I worked it out
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 mrbronz61 - Apr-10-2021, 09:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class Update input (Gpio pin raspberry pi) caslor 2 788 Jan-30-2023, 08:05 PM
Last Post: caslor
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,670 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