I wanted to create a tkinter function where you have some variables dependent upon time. I wanted it so that every so often the people variable will update with every increment of time. For this example I wanted to make it so that it mimicked customers coming into a store every 5 seconds. Thing is when I click on the menu for customers it doesn't update. How do I get it to update? The time.clock() function updates.
import time from Tkinter import * import tkMessageBox mGui = Tk() mGui.title("Experiment") mGui.geometry('450x450+500+300') def customers(): tkMessageBox.showinfo(title="Customers", message=people) def timer(): tkMessageBox.showinfo(title="Customers", message=time.clock()) people = time.clock()/5 label1 = Label(mGui, text = "label 1").pack() ##Menu menubar = Menu(mGui) filemenu = Menu(menubar, tearoff = 0) menubar.add_cascade(label="In Line", menu=filemenu) filemenu.add_command(label="Customers", command = customers) filemenu.add_command(label="Time", command = timer) mGui.config(menu=menubar) mGui.mainloop()
time.clock(), notime.sleep()onlytkinter.after(millisecond, function name)tkinter.afterto run everymillisecondinterval. Better to run some sort of timedelta function every short period of time and rely on that instead. Even if you're callingafter(5000, foo)and yourfoois running every 5,005ms, you're quickly running behind.