[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] new user
Hi.
break will break out of the most "recent" loop, which in this case is
"for".
however, you want to break out of the "while" loop.
-sjbrown
> import sys
> import pygame
> from pygame.locals import *
>
> def main():
> # Initialise screen
> pygame.init()
> screen = pygame.display.set_mode((150, 50))
> pygame.display.set_caption('Basic Pygame program')
>
> # Fill background
> background = pygame.Surface(screen.get_size())
> background = background.convert()
> background.fill((250, 250, 250))
>
> # Display some text
> font = pygame.font.Font(None, 36)
> text = font.render("Hello There", 1, (10, 10, 10))
> textpos = text.get_rect()
> textpos.centerx = background.get_rect().centerx
> background.blit(text, textpos)
>
> # Blit everything to the screen
> screen.blit(background, (0, 0))
> pygame.display.flip()
>
> # Event loop
> while 1:
> for event in pygame.event.get():
> if event.type == QUIT:
> foo
>
> screen.blit(background, (0, 0))
> pygame.display.flip()
>
>
> if __name__ == '__main__': main()
>
>
> Output:
> if foo == 'break': opens window, cannot close with quit 'x' click, even
> if PythonWin is quit... (can quit with task manager - says "Not
> Responding")
>
> if foo == 'sys.exit()':
> On quit, PythonWin sez (at bottom of it's window): "Exit code
> received". If you quit again, crashes pythonwin.exe. With the following:
>
> The instruction at "07x3dd1351" referenced memory at "0x00000004". The
> memory could not be "read".
>
> Thanks again. I guess this is not a big deal - just an extra step to
> save code (or edit in notepad), and run from command line / win exploader.
>
>
> Ben
> Josh Close wrote:
>
>> Well, can you post your code and the output then? That might make this
>> a little easier.
>>
>> -Josh
>>
>>
>> On Tue, 14 Sep 2004 12:17:17 -0700, Ben Hitz <hitz@avigne.org> wrote:
>>
>>>yes, the 2nd time. <grin>
>>>
>>>Ben
>>>
>>>
>>>
>>>Josh Close wrote:
>>>
>>>
>>>>Did you "import sys"?
>>>>
>>>>-Josh
>>>>
>>>>
>>>>On Tue, 14 Sep 2004 11:13:31 -0700, Ben Hitz <hitz@avigne.org> wrote:
>>>>
>>>>
>>>>>Thanks, but this doesn't work with python or PythonWin.
>>>>>
>>>>>Neither does:
>>>>>if event.type == QUIT:
>>>>> break
>>>>>
>>>>>within the event loop. However, it doesn't crash - just doesn't exit.
>>>>>
>>>>>Ben
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>Josh Close wrote:
>>>>>
>>>>>
>>>>>
>>>>>>On Mon, 13 Sep 2004 22:46:57 -0700, Ben Hitz <hitz@avigne.org> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Hey there.
>>>>>>>
>>>>>>>two quick questions:
>>>>>>>
>>>>>>>I seem to have pygame working fine, except that I have trouble
>>>>>>> quitting
>>>>>>>trivial Hello World apps from IDLE or pythonw (win). I am running
>>>>>>>python2.3.4 on Window XP.
>>>>>>
>>>>>>
>>>>>>for event in pygame.event.get():
>>>>>> if event.type == QUIT:
>>>>>> sys.exit()
>>>>>>
>>>>>>This will allow for you to click the 'x' to close the window.
>>>>>>
>>>>>>-Josh
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I have no problem if I just run the scripts directly
>>>>>>>
>>>>>>>Next question: Anyone have a "slider" widget? In my game, much of
>>>>>>> the
>>>>>>>player input I plan to do with a few sliders (like a scroll bar, but
>>>>>>>sets a specific scalar value)
>>>>>>>
>>>>>>>Thanks,
>>>>>>>
>>>>>>>Ben
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>
>>
>
>
----
Sent from geeky.net