Apr-09-2021, 04:26 PM
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 yowLabelUsing 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