繁体   English   中英

在 Tkinter 中是否有线程的替代方法? 或者有没有办法在没有线程的情况下运行后台计时器?

[英]Is there an alternative to threading in Tkinter? or is there a way to run a background timer without threading?

我是Tkinter新手,我的理解是我们不能将threadingTkinter一起使用。 所以我想知道是否有替代threading ,或者是否有一种简单的方法来运行后台计时器?
基本上我想在一段时间后用不同的元素替换我的root元素而不停止程序的执行。
这是我在意识到threading不是Tkinter一个选项之前尝试过的:

def checkGridElements():
    time.sleep(5)
    label1.grid_forget()
    label2.grid(row=0,column=0,sticky=E,padx=5,pady=5);passEntry.grid(row=0,column=1,sticky=W,padx=5,pady=5)
    return

t = threading.Thread(target=checkGridElements)
t.start()

根(所有小部件)有一个 after 方法,该方法允许在指定时间后调用函数,暂停 tk 循环。 如果您尝试使用线程,则可以尝试 tkthread ( https://pypi.org/project/tkthread/ )。 问题是 python 和 tcl/tk 有不同的线程系统。 tkthread 应该桥接它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM