[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Menu Selection



"Luke Paireepinart" <rabidpoobear@xxxxxxxxx>
> Simon Jackson wrote:
>> Hello, I want to make a program that lets you select an item from a
>> list. Check out the screenshot below for an example:
>>
>> http://lemonlauncher.sourceforge.net/snap/snap3.png
>>
>> Can anyone point me to a tutorial or something similar that will show
>> me how to do this?
> If you have a series of rects that describe the menu boxes, it's trivial
> to do a point-rect collision with your
> list of menu items and the coordinates of the mouse.
> Hints: pygame.mouse.get_pos()  and Rect.collidepoint(x,y)

That's exactly what I do for my menu code. If you don't mind wading
through a more-or-less complete game, you can see my main menu code here:
http://www.bigdicegames.com/Woody/BDG_07_04.zip

Look at stateMainMenu.py which is a menu (a couple of buttons), and then
there's stateNewGameMenu.py and stateOptions.py which look like modal
dialog boxes, but operate the same way.

The function in stateMainMenu.py to look at is "handleMouseButton" on line
165, which iterates over the buttons, and checks to see if the user has
clicked inside the widget, and if so, calls a method on the widget.


It's not a tutorial, but it might be useful.


-Dave LeCompte