0

I've written a command-base program and it works properly. Since I'd like to add some graphical interface, I prepared a simple one with Tkinter. But the line which contains "scheduler.run", it locks my application and I can't get any error code.

def do_deneme(p): etiket_run1["text"] = etiket_run1["text"] + str(p) + " completed at " + str(datetime.datetime.now()) def run_do(): ... scheduler=sched.scheduler(time.time, time.sleep) for p in clean_information: scheduler.enter(float(p[12]), 1, do_deneme,(p,)) etiket_run1["text"] = etiket_run1["text"] + str(datetime.datetime.now()) scheduler.run() etiket_run1["text"] = etiket_run1["text"] + "Completed." ... etiket_run1=Label(cerceve1, fg="red") etiket_run1.pack(side=BOTTOM,padx=5,pady=5) dugme = Button(cerceve2,text=u"Start",command=run_do) ... 

Any way to debug this code part? or any suggestion about using scheduler.run with labels in Tkinter?

1 Answer 1

0

Tkinter is single-threaded. It appears that your scheduler sleeps until it is time to run something, so while it is sleeping your GUI will lock up.

The proper way to run something in the future or on a schedule with Tkinter is to call after which uses the event loop to schedule something to run after a set amount of time. You can either call it once if you want something to run a fixed number of milliseconds later, or you can repeatedly call it until some condition. By repeated, I mean you use after to call a function which checks the condition; if the condition is false the function will call itself again with after. If the condition is true, it runs your job.

Sign up to request clarification or add additional context in comments.

2 Comments

Bryan, thanks for the info. But is it possible to use scheduler.run with other GUIs, like wxpython? or any simple example for "after" usage? Sorry but I'm pretty new to Tkinter and other GUIs.
@fish: see this answer for an example of using after: stackoverflow.com/questions/2400262/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.