按下按钮时激活倒数计时

时间:2019-10-28 18:26:24

标签: python python-3.x tkinter countdown

我正在使用Tkinter制作一个GUI程序,该程序记录您在10秒内进行的点击次数,并显示您每秒进行的点击次数(CPS)。我不知道为什么计时器不工作

from tkinter import *
root = Tk()
root.title("Click Speed Test")
root.geometry("600x600")

count = 10

label_1 = Label(root, text="Click in the square", font=("Arial", "30"))
label_1.pack()

label_2 = Label(root, text="to start the timer", font=("Arial", "20"))
label_2.pack()


def countdown():
    global count
    label_2['text'] = count

    if count > 0:
        root.after(1000, countdown, count-1)


button = Button(root, width=50, height=25, bg="Light Grey", command=countdown)
button.pack()

root.mainloop()

我希望按下按钮时计时器会启动,但会出现错误。

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\Sam\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Users\Sam\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 749, in callit
    func(*args)
TypeError: countdown() takes 0 positional arguments but 1 was given

0 个答案:

没有答案