Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误:';int';对象没有属性';在'之后;_Python_Python 3.x_Tkinter - Fatal编程技术网

Python 属性错误:';int';对象没有属性';在'之后;

Python 属性错误:';int';对象没有属性';在'之后;,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我试着在用Tkinter制作的游戏中加入计时器 from tkinter import * timer = 60 def startGame(event): if timer == 60: countdown() def countdown(): global timer if timer > 0: timer -= 1 timeLabel.config(text='Time left:' + str(timer))

我试着在用Tkinter制作的游戏中加入计时器

from tkinter import *
timer = 60
def startGame(event):
    if timer == 60:
        countdown()
def countdown():
    global timer
    if timer > 0:
        timer -= 1
        timeLabel.config(text='Time left:' + str(timer))
        timer.after(1000, countdown())
window = Tk()
timeLabel = Label(window, text='time = 60 sec')
entryBox = Entry(window)
timeLabel.pack()
entryBox.pack()
window.bind('<Return>', startGame)
entryBox.pack
entryBox.focus_set()
window.mainloop()
我试着将计时器转换为字符串和浮点

str(timer).after(1000, countdown())     in line11
如果这3个属性(int、str和float)不起作用,那么哪个属性将与“entry”一起起作用


或者如何在游戏中添加计时器?

为了消除所有的困惑,
after()
root
的一种方法,而不是
timer
,在您的例子中是int。只需将(…)之后的
计时器替换为root.after(…)


确保从
倒计时()
中删除
()
,以便在1000毫秒之前不会调用该命令。

整数、浮点或字符串都没有名为“after”的方法。你能解释一下为什么你期望这种方法存在吗?我在另一篇关于为游戏添加计时器的帖子上看到了这一点。你问的也是我的问题。那我该怎么做呢。或者至少在我的游戏中添加一个计时器。不管你想调用什么方法。第二个参数需要是
countdown
,而不是
countdown()
。您希望计时器调用函数,而不是在那里调用。请尝试
window.after(1000,countdown())
是的,这很有效。谢谢你能补充一下吗?这样其他人也能找到。再次感谢。
str(timer).after(1000, countdown())     in line11
float(timer).after(1000, countdown())   in line11
if timer > 0:
    timer -= 1
    timeLabel.config(text='Time left:' + str(timer))
    timer.after(1000, countdown)