【问题标题】:Tkinter GUI freeze when running method (How to add threading?)运行方法时 Tkinter GUI 冻结(如何添加线程?)
【发布时间】:2018-10-29 02:43:06
【问题描述】:

很抱歉打扰您,但我想寻求帮助。当我调用 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''')

【问题讨论】:

    标签: python multithreading tkinter


    【解决方案1】:

    从问题中不清楚“我尝试添加线程,但它没有按预期工作。”是什么意思。

    无论如何,请检查此帖子: http://stupidpythonideas.blogspot.com/2013/10/why-your-gui-app-freezes.html

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

    【讨论】:

      猜你喜欢
      • 2011-01-28
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      • 2021-04-19
      • 2015-04-08
      • 2022-06-21
      • 2019-05-10
      相关资源
      最近更新 更多