Python 使用Tkinter在特定时间打印值

Python 使用Tkinter在特定时间打印值,python,tkinter,Python,Tkinter,我已经编写了一个命令库程序,它工作正常。因为我想添加一些图形界面,所以我用Tkinter准备了一个简单的界面。但是包含“scheduler.run”的行会锁定我的应用程序,我无法获得任何错误代码 def do_deneme(p): etiket_run1["text"] = etiket_run1["text"] + str(p) + " completed at " + str(datetime.datetime.now()) def run_do(): ... sc

我已经编写了一个命令库程序,它工作正常。因为我想添加一些图形界面,所以我用Tkinter准备了一个简单的界面。但是包含“scheduler.run”的行会锁定我的应用程序,我无法获得任何错误代码

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)
...

有没有办法调试这个代码部分?或者关于在Tkinter中使用scheduler.run with labels的任何建议?

Tkinter是单线程的。您的调度程序似乎一直处于休眠状态,直到运行某项操作为止,因此当它处于休眠状态时,您的GUI将被锁定


使用Tkinter在将来或计划中运行某些内容的正确方法是调用
after
,它使用事件循环计划某些内容在设定的时间量之后运行。如果希望某个东西在固定的毫秒数后运行,可以调用它一次,也可以重复调用它直到出现某种情况。通过重复,我的意思是在之后使用
调用检查条件的函数;如果条件为false,函数将在
之后使用
再次调用自身。如果条件为真,它将运行您的作业。

Bryan,谢谢您提供的信息。但是,是否可以将scheduler.run与其他GUI一起使用,比如wxpython?或者“after”用法的简单示例?很抱歉,我对Tkinter和其他GUI非常陌生。@fish:有关使用after的示例,请参见此答案: