将类从线程更改为非线程

问题描述

我让tkinter成功地在线程中运行。我知道你不应该,所以我想将我的线程类“转换”为非线程版本并执行它。我将使用root.after(而不是root.mainloop)尝试停止TKinter阻塞(这是线程的初衷,因为我在代码的其他地方有While真正的循环)。

有人可以指出我需要更改代码的哪些位以使其成为非线程吗? “普通的python类”使我感到困惑。

class guipart(threading.Thread):
        
   def __init__(self):
        threading.Thread.__init__(self)
        self.event = threading.Event()
        
   def closetk():
        GPIO.output(26,GPIO.LOW)
        win.destroy()
     
   def run(self):
        while not self.event.is_set():
                               
                global val,w,root,alarm_var
                root = tk.Tk()
                              
                alarm_var = tk.StringVar(root)
                alarm_var.set('Scanning Doors')
                              
                top = Toplevel1 (root)
                reDalert_support.init(root,top)
                                               
                #root.after(0,guipart)
                root.mainloop()
                w = None

    guiloop = guipart()
    guiloop.start()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)