Line 11: AttributeError: list instance has no attribute '__index__' or '__int__'

52 views Asked by At

I'm trying to make a program that displays the time left on the timer using "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()
2

There are 2 answers

0
diaa On BEST ANSWER

You are using the timer incorrectly. timer_handler is the function that's called every time your timer 'ticks'. You have to create the timer outside the function and then pass the handler as a parameter.

As to displaying the time, you have to create a global variable and then increment it from within the handler like this:

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()
0
Wondercricket On

You have too many parenthesis at the end of the line. As such, the arguments for draw_text are being passed in as arguments for int

canvas.draw_text(int(message), [50,112], 48, "Red")
                            ^ Move the trailing parenthesis here