[Tutor] A range of numbers

Leung Cris krazie_mu_boi at hotmail.com
Mon Dec 1 20:46:30 EST 2003


Forgot to tell you guys, if I don't get my mouse to the graphics screen, the mouse_position() will return None instead of a (x,y) . here's the error I wud get:

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in ?
    func()
  File "<pyshell#0>", line 6, in func
    x,y = mouse_position()
TypeError: unpack non-sequence


>From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
>To: Cris Leung <krazie_mu_boi at hotmail.com>
>CC: tutor at python.org
>Subject: Re: [Tutor] A range of numbers
>Date: Mon, 1 Dec 2003 17:43:49 -0800 (PST)
>
>
>
>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!
>

_________________________________________________________________
¨Ï¥Î MSN Messenger¡A»PªB¤Í¦b½u¤W²á¤Ñ: http://messenger.microsoft.com/tc 




More information about the Tutor mailing list