python - Tkinter:root.after(), root.after_cancel()

标签 python user-interface tkinter tcl tk-toolkit

我有这个秒表,我试图在计数达到 0 后重置它。但是我在使用“after_cancel”功能时遇到了问题。谁能帮忙?
发生的是它无休止地继续,我想杀死“之后”功能。

def countdown(self):
    if self.totalseconds == 1:
        self.master.after_cancel(self.after_id)
    self.totalseconds = self.totalseconds - 1
    stdtime = self.total_seconds_to_standard(self.totalseconds)
    self.time.set(stdtime)
    self.after_id = self.master.after(1000,self.countdown)

最佳答案

想通了……foobar。

def countdown(self):
    self.totalseconds = self.totalseconds - 1
    stdtime = self.total_seconds_to_standard(self.totalseconds)
    self.time.set(stdtime)
    self.after_id = self.master.after(1000,self.countdown)
    if self.totalseconds == 0:
        self.master.after_cancel(self.after_id)

关于python - Tkinter:root.after(), root.after_cancel(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52031267/

相关文章:

c# - 如何为 windows7、wpf 构建自定义 shell?

java - 如何按每行中的值对存储在文本文件中的条目进行排序

python - Scrapy FormRequest 发送 JSON

Python MySQLdb 无法连接到服务器,SSL 问题

user-interface - 设置kendo ui dropdownlist宽度

python - 居中窗口python tkinter

python - 制作一个可以被多个按钮使用的功能

python - 如何更新 Canvas 上的图像?

python - Django Model.objects.all() 返回意外的空 QuerySet

Python Imaging,如何将图像量化为 16 位深度?