[Tutor] A range of numbers

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Dec 1 20:43:49 EST 2003



On Mon, 1 Dec 2003, Danny Yoo wrote:
> > delay"  is finish. However, if I dun click within seconds after the
> > "print 'delay'"  , the thing freezes.
>
>
> Ah!
>
> Try moving the begin_mouse() and end_mouse() stuff around the
> mouse_position().  What's happening is that begin_mouse() and
> end_mouse() are the function that update the mouse position in the
> program. Without them, mouse_position() will continue to return the same
> thing over and over.
>
>
> ###
> def func():
>     begin_graphics()
>     box(200,200,300,300)
>     while 1:
>         begin_mouse()
>         x,y = mouse_position()
>         end_mouse()
>         if (200 <= x <= 300
>             and 200 <= y <= 300
>             and mouse_buttons()['left'] == 1):
>             break
>     box(100,100,400,400)
> ###
>
> should fix the bug.



Doh.  I meant:


###
def func():
    begin_graphics()
    box(200,200,300,300)
    while 1:
        begin_mouse()
        x,y = mouse_position()
        buttons = mouse_buttons()
        end_mouse()
        if (200 <= x <= 300 and 200 <= y <= 300
            and buttons['left'] == 1):
            break
    box(100,100,400,400)
###


That is, we need to wrap the begin_mouse() and end_mouse() around all
mouse access.  Otherwise, mouse_buttons() isn't guaranteed to give us a
good value.


Sorry about that!




More information about the Tutor mailing list