Line 11: AttributeError: list instance has no attribute '__index__' or '__int__'
Line 11: AttributeError: list instance has no attribute '__index__' or '__int__'
我正在尝试制作一个程序,使用 "import simplegui" 显示计时器上的剩余时间。
import simplegui
def timer_handler():
timer = simplegui.create_timer(500, timer_handler)
timer.start()
message = simplegui.create_timer
def draw(canvas):
canvas.draw_text(int(message, [50,112], 48, "Red")) #Line where I get the error.
frame = simplegui.create_frame("Home", 300, 200)
frame.set_draw_handler(draw)
frame.start()
行尾的括号太多。因此,draw_text
的参数作为 int
的参数传入
canvas.draw_text(int(message), [50,112], 48, "Red")
^ Move the trailing parenthesis here
您没有正确使用计时器。 timer_handler
是每次计时器 'ticks' 时调用的函数。您必须在函数外部创建计时器,然后将处理程序作为参数传递。
至于显示时间,您必须创建一个全局变量,然后像这样在处理程序中递增它:
import simplegui
time = 0
def timer_handler():
global time
time += 1
timer = simplegui.create_timer(500, timer_handler)
timer.start()
def draw(canvas):
canvas.draw_text(str(time), [50,112], 48, "Red") #Line where I get the error.
frame = simplegui.create_frame("Home", 300, 200)
frame.set_draw_handler(draw)
frame.start()
我正在尝试制作一个程序,使用 "import simplegui" 显示计时器上的剩余时间。
import simplegui
def timer_handler():
timer = simplegui.create_timer(500, timer_handler)
timer.start()
message = simplegui.create_timer
def draw(canvas):
canvas.draw_text(int(message, [50,112], 48, "Red")) #Line where I get the error.
frame = simplegui.create_frame("Home", 300, 200)
frame.set_draw_handler(draw)
frame.start()
行尾的括号太多。因此,draw_text
的参数作为 int
canvas.draw_text(int(message), [50,112], 48, "Red")
^ Move the trailing parenthesis here
您没有正确使用计时器。 timer_handler
是每次计时器 'ticks' 时调用的函数。您必须在函数外部创建计时器,然后将处理程序作为参数传递。
至于显示时间,您必须创建一个全局变量,然后像这样在处理程序中递增它:
import simplegui
time = 0
def timer_handler():
global time
time += 1
timer = simplegui.create_timer(500, timer_handler)
timer.start()
def draw(canvas):
canvas.draw_text(str(time), [50,112], 48, "Red") #Line where I get the error.
frame = simplegui.create_frame("Home", 300, 200)
frame.set_draw_handler(draw)
frame.start()