跑步时间。睡觉()在另一个线程上冻结Tkinter程序

2024-03-29 10:00:12 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想逃跑时间。睡觉()在另一个线程上,但调用该函数时整个程序仍然冻结。我用按钮叫它。这是为了创建一个错误,然后等待几秒钟来删除错误。不知道还能做什么。在

import threading, time

class Block():    
    def createError(self, text):
        background.itemconfig(errorText, text=text, state=NORMAL, font="Neoteric 11 bold")
        background.itemconfig(errorBG, state=NORMAL)

        # Mainly this part to worry about
        t = threading.Thread(target=self.removeError())
        t.start()
        print("Function called") # Only prints AFTER 5 seconds, even though removeError() should be running on another thread

    def removeError(self):
        time.sleep(5)
        background.itemconfig(errorText, text="", state=HIDDEN)
        background.itemconfig(errorBG, state=HIDDEN)

# Tkinter stuff here to create button and run createError()

任何想法都会很棒!在


Tags: totextselftimedef错误backgroundstate
1条回答
网友
1楼 · 发布于 2024-03-29 10:00:12

我想出来了。我所要做的就是在线程内部使用不同的函数。在

交换: 在

t = threading.Thread(target=self.removeError())
t.start()

收件人: 在

^{pr2}$

就这样。工作起来很有魅力!在

相关问题 更多 >