首页 > 解决方案 > 如果触发了某个标志,我想停止一个方法而不完成它的指令

问题描述

我有一个每隔几秒钟显示一个顶层窗口的方法,无论如何,如果用户单击关闭按钮而不是确定按钮,则不应显示剩余的顶层窗口。在下面的代码中 disAction() 是关闭按钮的命令

我尝试使用 while 循环,它显示“未响应”错误

def topRequester(self):
if self.dismiss == 0:
    self.after(SLEEP_SEC, self.toplevelmaker)
    self.after(SLEEP_SEC + SLEEP_SEC, self.toplevelmaker)
    self.after(SLEEP_SEC + SLEEP_SEC*2, self.toplevelmaker)
    self.after(SLEEP_SEC + SLEEP_SEC*2, self.topRequester)

def disAction(self):  # the cycle should be disrupted
    self.topwin.withdraw()
    self.dismiss = 1

标签: pythontkinterreturn

解决方案


推荐阅读