user interface - python- using delay between tkinter's listbox prints -
all want make time delay between each print on listbox included on gui . havent managed result far. tried use time.sleep () ... , after method.
here code :
from tkinter import * def func() : = int (e.get()) x in range (0,i): listbox.insert (end, i) i-=1 master = tk() master.title("hi") e=entry (master ) e.pack() listbox = listbox(master) listbox.pack() b = button(master, text="get", width=10, command=func) b.pack() mainloop()
when you're using gui, should use after
instead of sleep. if sleep, gui stop updating, won't refreshed displays , nothing work want to.
to desired result in code, have several options. 1 of them using after
call function inserts listbox , pass new argument each iteration.
first, you'll have modify button command pass initial argument function using lambda
expression:
b = button(master, text="get", width=10, command=lambda: func(int(e.get())))
next, structure function this:
def func(arg): listbox.insert(end, arg) #insert arg arg -= 1 #decrement arg master.after(1000, func, arg) #call function again after x ms, modified arg
note: you'll need make function return
if arg
less 0
, or it'll run forever ;)
Comments
Post a Comment