Tkinter的:root.after(),root.after_cancel()

时间:2018-08-27 00:29:48

标签: python user-interface tkinter tcl tk

在计数达到0之后,我试图重置此秒表。但是,使用“ after_cancel”函数时遇到了麻烦。有人可以帮忙吗?
发生的事情是它不断地继续下去,我想杀死“ after”函数。

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)

1 个答案:

答案 0 :(得分:-1)

想通了... 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)