如何修复python GUI中的无响应错误

如何修复python GUI中的无响应错误,python,user-interface,Python,User Interface,我想为python脚本制作一个GUI,但当我按下start时,GUI中没有响应 layout = [[sg.Output(size=(60,10))], [sg.Button('Exit'),sg.Button('Start')]] window = sg.Window('Window Title', layout) event, values = window.read() while True: if event == sg.WIN_CLOSED or event == '

我想为python脚本制作一个GUI,但当我按下start时,GUI中没有响应

layout = [[sg.Output(size=(60,10))],
    [sg.Button('Exit'),sg.Button('Start')]]

window = sg.Window('Window Title', layout)
event, values = window.read()
while True:
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'Start':                  
        for email in emails:                                                                                  
            if counter < 2:                
                if len(email.strip()) > 0:
                    with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
                        server.login(sender_email, password)
                        try:
                            server.sendmail(
                                sender_email, email, message.as_string()
                            )
                            #print("Adresa " + email + " este corecta!")
                        except smtplib.SMTPDataError:
                                track +=1                               
                                print("Prea multe email-uri trimise")
                                print("Adresa de email " + sender_email + " a fost inlocuita cu " + sender_mails[track] + " !")
                                emails.append(email)
                                sender_email = sender_mails[track]
                        except smtplib.SMTPRecipientsRefused:
                            print("Adresa " + email + " nu este corecta!")
                            #counter += 1
                        except:
                            print ("Eroare necunoscuta")
            else:
                while time.time() - start_time <= 60:
                    pass
            if time.time() - start_time >= 60:
                start_time = time.time()
                counter = 0
                emails.append(email)
        break                                                                       
window.close()
layout=[[sg.Output(size=(60,10))],
[sg.按钮('Exit')、sg.按钮('Start')]]
窗口=sg.window('窗口标题',布局)
事件,值=window.read()
尽管如此:
如果事件==sg.WIN\u关闭或事件==退出:
打破
如果事件==“开始”:
对于电子邮件中的电子邮件:
如果计数器<2:
如果len(email.strip())>0:
使用smtplib.SMTP_SSL(“SMTP.gmail.com”,465,context=context)作为服务器:
服务器登录(发件人\电子邮件、密码)
尝试:
server.sendmail(
发件人\电子邮件、电子邮件、消息。作为\字符串()
)
#打印(“Adresa”+电子邮件+“este corecta!”)
除了smtplib.SMTPDataError:
轨道+=1
打印(“预打印电子邮件uri trimise”)
打印(“电子邮件地址”+发件人电子邮件+“一个fost Inlocita cu”+发件人电子邮件[跟踪]+“!”)
电子邮件。附加(电子邮件)
发件人\电子邮件=发件人\邮件[跟踪]
除smtplib.SMTPrecipients外:
打印(“Adresa”+电子邮件+“nu este corecta!”)
#计数器+=1
除:
印刷品(“Eroare necunoscuta”)
其他:
而time.time()-start_time=60:
开始时间=time.time()
计数器=0
电子邮件。附加(电子邮件)
打破
window.close()

这是密码。。在我按下启动脚本后,我无法关闭它。我用的是PySimpleGUI。按下开始按钮后,GUI将冻结,直到开始语法中的所有操作完成。我希望能够在执行这些操作时使用该界面。

因此我没有运行您的代码,但我想您的while循环会冻结您的代码:

其他:

while time.time()-start\u time如果长时间执行某项操作,GUI将不会响应。最好的方法是使用多线程并调用
窗口。写入事件值(key,value)
以生成事件

从这里,您可以找到11个文件名为startswith
Demo\u multi-threaded_xxxx.py
的脚本来演示多线程


您在GUI中使用什么库?也可能是因为while-True循环,如果计数器<2:
必须为false,程序就无法从中跳出
。。。因此,代码在此处等待60秒:
while time.time()-start_time@matiss我使用PySimplegui他无法输入该值,因为计数器现在不递增。#计数器+=1所以计数器保持0在哪里初始化
计数器
?不在上面显示的代码中…thx。我用多线程解决了这个问题