Tkinter after()函数显示异常行为

时间:2017-11-23 12:45:19

标签: python python-3.x tkinter

from tkinter import *
##from sys import exit

class Timer:
    def __init__(self, master):
        self.master=master
        buttonstart = Button(master, text = "Start", fg = "blue", command = self.start)
        buttonstart.grid(row = 1, column = 0)

        buttonquit = Button(master, text = "Quit", fg = "blue", command=self.quitit)
        buttonquit.grid(row = 1, column = 2)

        self.timertext = DoubleVar()
        self.timertext.set(0)
        display = Label(master, textvariable = self.timertext)
        display.grid(row = 0, column = 0)    
        self.timeit=False

    def increment_timer(self):
        if self.timeit:
            ctr=int(self.timertext.get())
            self.timertext.set(ctr+1)
            self.master.after(3000, self.input_delay)
            self.master.after(4000, self.output_delay)
        if self.timeit:
            self.master.after(5000, self.increment_timer)

    def input_delay(self):
        print("Input Delay")

    def output_delay(self):
        print("Output Delay")

    def start(self):
        self.timeit=True
        self.increment_timer()

    def quitit(self):
        self.timeit=False

root = Tk()
app = Timer(root)
root.mainloop()

在increment_timer()方法中,5000的延迟工作正常但延迟3000和4000根本不起作用。如果我将5000的延迟更改为0,那么它只会继续给出input_delay方法的结果。我想在3秒延迟后调用input_delay,然后在每次迭代后4秒延迟后调用output_delay。很好地将5000改为0,因为我不想在那里延迟,而是我想在每次迭代中两次延迟。请指导我......

0 个答案:

没有答案