Tkinter GUI在运行时冻结方法(如何添加线程?)

时间:2018-10-29 02:43:07

标签: python multithreading tkinter

很抱歉打扰您,但我想寻求帮助。当我调用Neural_network方法时,我的tkinter应用程序冻结,因为它中断了主循环。我试图添加线程,但是它没有按预期工作。如果有人可以帮助我,我将非常感激。谢谢!

class Toplevel1:
def __init__(self, top=None):
    def neural_network(p1,p2,p3,p4,p5):
        #NEURAL NETWORK STUFF GOING ON HERE
        print(round(prediction.item(0)))
        if round(prediction.item(0)) == 1: self.Label1_6.configure(text='''Malignant''', foreground="red")
        else: self.Label1_6.configure(text='''Benign''', foreground="green")

    def call_neural(p1, p2, p3, p4, p5):
        self.Label1_6.configure(text='''Please wait...''', foreground="black")
        root.after(10000, neural_network(p1, p2, p3, p4, p5))

    def analytics():
        try:
            float(self.Entry1_3.get())
            float(self.Entry1_4.get())
            float(self.Entry1_5.get())
            float(self.Entry1_6.get())
            float(self.Entry1_7.get())
            p1 = (float(self.Entry1_3.get()) - 6.981) / (21.129)
            p2 = (float(self.Entry1_4.get()) - 43.79) / (144.71)
            p3 = (float(self.Entry1_5.get()) - 143.5) / (2357.5)
            p4 = (float(self.Entry1_6.get()) - 0.01938) / (0.32602)
            p5 = (float(self.Entry1_7.get()) - 0) / (0.4268)
            if 0 <= p1 <= 1 and 0 <= p2 <= 1 and 0 <= p3 <= 1 and 0 <= p4 <= 1 and 0 <= p5 <= 1: call_neural(p1, p2, p3, p4, p5)
            else:  self.Label1_6.configure(text='''Error: Out of bounds''')
        except ValueError:
            self.Label1_6.configure(text='''Please fill all fields''')

1 个答案:

答案 0 :(得分:0)

从这个问题尚不清楚,您的意思是“ 我试图添加线程,但是没有按预期工作。

无论如何,请检查以下信息: http://stupidpythonideas.blogspot.com/2013/10/why-your-gui-app-freezes.html

它解释了各种方法(包括线程方法),这些方法可用于在执行其他工作时使GUI保持响应。希望对您有所帮助。