[Tutor] A range of numbers

Leung Cris krazie_mu_boi at hotmail.com
Tue Dec 2 11:31:37 EST 2003


Ya, that's true.... but even if i change it something like this:
>>def func():
>>         begin_graphics()
>>         box(200,200,300,300)
>>         begin_mouse()
>>         while 1:
>>                 
>>                 try:
>>                         x,y = mouse_position()
>>                 except:
>>                         x,y = 0,0
>>                 if 200 <= x <= 300 and 200 <= y <= 300 and mouse_buttons()['left'] == 1:
>>                         break                        
>>         end_mouse()
>>         box(300,200,500,500)

It sill won't work. I've also tried putting time.sleep(0.05) before the while loop ends , but it ....still freezes.

>From: Alfred Milgrom <fredm at smartypantsco.com>
>To: "Leung Cris" <krazie_mu_boi at hotmail.com>, tutor at python.org
>Subject: Re: [Tutor] A range of numbers
>Date: Tue, 02 Dec 2003 18:14:07 +1100
>
>Hi Leung:
>
>It's better to use "reply to all" in future, so your comments get 
>posted to the list as well, rather than just to the one person.
>(I am copying this answer to the list now as well.)
>
>Looking at your code, I am not sure what you think the end_mouse() 
>code will do, but there is a logic mistake.
>
>Look at these lines:
>
>>                 if 200 <= x <= 300 and 200 <= y <= 300 and 
>>mouse_buttons()['left'] == 1:
>>                         break
>>                         end_mouse()
>>                 end_mouse()
>
>Translation:
>
>If the left button has been pressed inside the box:
>         break           <=== This means 'break out of the while 
>loop'.
>
>         No further code in the "while 1" loop will be executed, 
>including end_mouse()
>
>(continuing with the code):
>On the other hand, if the mouse is not in the box or if the mouse 
>button has not been pressed
>         end_mouse()     <=== Ignore all further mouse presses.
>
>So let's see what happens if that the program gets started:
>         Immediately the "if" test will fail (because you can't 
>press the cursor fast enough)
>         All further mouse presses get ignored
>         But you are still in the "while 1" infinite loop!
>
>Hope this helps,
>Fred Milgrom
>
>At 09:53 PM 1/12/03 -0800, you wrote:
>>I think i got the try ... except concept, but did i do something 
>>wrong here? cuz it freezes when i try this function
>>
>>_________
>>def func():
>>         begin_graphics()
>>         box(200,200,300,300)
>>         while 1:
>>                 begin_mouse()
>>                 try:
>>                         x,y = mouse_position()
>>                 except:
>>                         x,y = 0,0
>>                 if 200 <= x <= 300 and 200 <= y <= 300 and 
>>mouse_buttons()['left'] == 1:
>>                         break
>>                         end_mouse()
>>                 end_mouse()
>>         box(300,200,500,500)
>>________________
>>
>
>

_________________________________________________________________
¦b±zªº¦æ°Ê¸Ë¸m¤W¶Ç°e±µ¦¬ Hotmail ¶l¥ó¡A½Ð²¾¦Ü: http://zh-asiasms.mobile.msn.com 




More information about the Tutor mailing list