运行方法时 Tkinter GUI 冻结(如何添加线程?) [英] Tkinter GUI freeze when running method (How to add threading?)

查看:57
本文介绍了运行方法时 Tkinter GUI 冻结(如何添加线程?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Sorry for bothering you, but I would like to ask for help. My tkinter application freezes when I'm calling my Neural_network method because it interrupts the main loop. I tried to add threading, but it did not work as intended. If someone could help me out I would really appreciate it. Thank you!

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''')

推荐答案

从问题中不清楚我尝试添加线程,但没有按预期工作."

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

Anyways please check this post: http://stupidpythonideas.blogspot.com/2013/10/why-your-gui-app-freezes.html

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

It explains about various methods(including the threading method) which can be used to keep your GUI responsive while doing other work. Hope it helps.

这篇关于运行方法时 Tkinter GUI 冻结(如何添加线程?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆