python - Unexplained Infinite Loop in Tkinter -
i learning tkinter python2 came across code.this creates window in tkinter , increments value of label every 1 second while code runs fine..can tell me why infinite loop not observed after every thousand seconds control return count()
, control should have never reached last line of code?
import tkinter tk counter = 0 def counter_label(label): def count(): global counter counter += 1 label.config(text=str(counter)) label.after(1000, count) count() root = tk.tk() root.title("counting seconds") label = tk.label(root, fg="green") label.pack() counter_label(label) button = tk.button(root, text='stop', width=25, command=root.destroy) button.pack() root.mainloop()
also label variable passed function def counter_label
copy of original variable changing shouldnot affect original variable.how happening?
any appreciated.
- 1000 measured in milliseconds i.e., 1 second
count()
reached , infinite loop (ifroot.mainloop()
running).
label.after(1000, count)
schedules count
function , returns immediately. tkinter event loop should running otherwise count()
won't called again.
Comments
Post a Comment