Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

collect mouse lifts - 'NoneType' object is not iterable

The task: Participants shall press a mouse button to get into a starting position. They shall keep the button pressed and keep the mouse at a certain position (finally i want to do that on a touchscreen).
Then a traffic light appears as a starting counter like 5,4,3,2,1,go!
At the moment it does not go on to 4. Why is the for loop not working?

Image = canvas()
Image['startRect'] = Rect(x=0, y=242, w=159, h=159, color='blue', penwidth=10)
def TRIALhalf1(): #1st part of a trial
    shuffle (delay)
    start = [995,995,995,995,500] #delay[1] instead of 500
    my_mouse = Mouse(visible=True)
    while True: #press Mouse and keep it pressed
        button, (x, y), time = my_mouse.get_click()
        if (x, y) in Image['startRect']:
    for i in range(5):
        t0 = red[i].show() #timer goes on #red is a list of canvas
        #if Mouse is lifted start again
        my_mouse = Mouse(visible=True) #is this line necesary?
        button, (x, y), time_key_up = my_mouse.get_click_release(timeout=500) #start[i] #THIS IS THE PROBLEMATIC LINE
        if button != None:

TypeError: 'NoneType' object is not iterable

What am i doing wrong? Any ideas?


  • Hi,

    Let's focus on the (x, y) part of this line:

    button, (x, y), time_key_up = my_mouse.get_click_release(timeout=500)

    If a timeout occurs, the second return value will be None, and not an x, y tuple. Trying to assign None to the x, y tuple results in the error. Try to execute x, y = None in the debug window; you'll get the same error.

    So this should solve the issue:

    button, xy, time_key_up = my_mouse.get_click_release(timeout=500)


Sign In or Register to comment.