所以我有这个按钮来启动东西,像这样
self.buttontext = StringVar()
self.buttontext.set("Start")
self.button = Button(self.bottomframe, textvariable=self.buttontext, command=self.start)
当它启动时,我希望用户能够在需要时将其缩短,方法是在启动后立即将相同的按钮更改为停止按钮
def start(self):
self.button.config(command=self.stop)
self.buttontext.set("Stop")
permission = True
for ...
if update:
run properly
else:
end prematurely
self.button.config(command = self.start)
self.buttontext.set("Start")
这在循环的每次迭代中都考虑了一个布尔值。stop 函数会将 update 更改为 false 以便循环
def stop(self):
permission = False
但是,在我单击“开始”之后,我猜控制不再在主循环中并且按钮没有响应,尽管按钮在运行时期间更改了它的属性。我怎样才能使按钮响应,以便它可以被打断?