Python Tkinter在单击按钮并保持按下状态时崩溃

Python Tkinter在单击按钮并保持按下状态时崩溃,python,tkinter,Python,Tkinter,我有一个带有开始和退出按钮的简单程序。“开始”按钮使用win10toast发出通知,但按钮仍被明显按下,窗口变得无响应。按下开始按钮之前,退出按钮工作正常。这是我的密码: from tkinter import * from win10toast import ToastNotifier root = Tk() def exit_p(): exit() def new(): hr.show_toast("New", "Alert"

我有一个带有开始和退出按钮的简单程序。“开始”按钮使用win10toast发出通知,但按钮仍被明显按下,窗口变得无响应。按下开始按钮之前,退出按钮工作正常。这是我的密码:

from tkinter import *
from win10toast import ToastNotifier


root = Tk()


def exit_p():
    exit()

def new():
    hr.show_toast("New", "Alert")
    return


#creates a label widget
myLabel1 = Label(root, text="Full Moon Notification!")
myLabel2 = Label(root, text="Here you can start and exit the program")

button1 = Button(root, text="Start",padx=50,command=new).grid(row=3,column=0)
button2 = Button(root, text="Exit", padx=50,command=exit_p).grid(row=4,column=0)


#puts the widget on the screen
myLabel1.grid(row=0,column=0)
myLabel2.grid(row=1,column=0)

#loop to keep program running
root.mainloop()

问题可能是因为
hr.show\u toast(“新建”、“警报”)
阻塞

win10toast
库方便地提供了一个选项
threaded=True
,因此只需将该代码更改为

hr.show_toast("New", "Alert", threaded=True)

应该可以工作。

尝试在那里添加
threaded=True
。我对这两种方法都不是很熟悉,但我猜这是因为事件循环被阻塞了。可能是因为您实际上没有在
按钮中调用该方法。请尝试设置
command=new()
@sshah98:不,这完全是错误的。两年前有一个问题提出了。解决方法是设置
threaded=True
@user202729解决它!'hr.show_toast(“新建”、“警报”,threaded=True)”很有效,谢谢!