I'm making a game that needs to be able to pop up gui elements within a pygame surface. This question isn't what I want because wxPython goes around the SDL surface, not inside it. So far I've only seen ocemp, pgu, and GooeyPy in this problem space.
- Ocemp is huge and crufty looking. It mentions Python 2.3 and the newest file I found in a quick browse of the cvs repo was 2 years old.
- I couldn't get GooeyPy to work (though I didn't try very hard; eggs and Debian are not friends) and v0.2 was last updated in February of 2009.
- I've been working with pgu, but it appears to be unmaintained (last update 11/2009 and original maintainer abandoned it) and it's starting to show its age. It uses old style classes and throws string exceptions.
So my question to you, SO, is this: What gui toolkit should I use for making pretty clickable buttons pop up in your pygame applications? Are there any in active development?
Edit, September 2011
It looks like PGU is still being maintained. The last commits are from 4 days ago.
I'm not aware of any pygame gui stuff, but it shouldn't be terribly hard to roll your own (and hey, maybe make it open source!)
If you're just doing a few simple buttons you could use GIMP or Photoshop or something else to make two (or three) images - an up, down and possible hover button, then you'd write your own event loop/handler that would do something like this:
- Get the mouse position
- Is the mouse over any of the buttons (and no buttons are pressed)?
- Display hover image
- Is the mouse over a button and a mouse button is clicked?
- Fire event associated with that button
- See 1
That's a bit simplified, but it should at least give you a starting point (if no one else has any pygame GUI libraries)
Despite this being old, you really don't have to have a gui library for it, you just use sprites. For labels you would take a sprite and give it the font to render and such. For buttons it inherits the label and adds a active state to detect changes and cause something else to happen. And a scroller works the same as a button and just changes a label or something elses value
Albow from the python wiki
http://wiki.python.org/moin/PythonGameLibraries
See also the answers to:
What's the best way to add a GUI to a Pygame application?
In particular, if someone would like to use DavesGUI, my pre-beta GUI toolkit for PyGame, send me an email. There's a link to my email address at the end of my reply, there.
I created a function that you can use inside of pygame without importing any extra libraries.
def gui(x1, y1, x2, y2, button):
mouseX, mouseY = pygame.mouse.get_pos()
if mouseX >= x1 and mouseX <= x2 and mouseY >= y1 and mouseY <= y2:
if button:
return True
else:
return False
else:
return False
You call upon the function like so(I am using a menu as an example).
topCornerX = #X coordinate of top right corner
topCornerY = #Y coordinate of top right corner
bottomCornerX = #X coordinate of bottom left corner
bottomCornerY = #Y coordinate of bottom left corner
while menu:
for event in pygame.event.get():
mouseLeft, mouseMiddle, mouseRight = pygame.mouse.get_pressed()
if gui(topCornerX, topCornerY, bottomCornerX, bottomCornerY, '''mouseLeft, mouseMiddle, or mouseRight''')
menu = False
Then you would continue on with your output.
This works by taking the coordinates of a rectangle and comparing your mouse postion to the inside of the rectangle and is True if they click the correct button and are inside the rectangle. Hope this helps.
I agree with milleja46 on not using a gui for somethings,
I found 2 simple menu popup programs here instead:
sophisticated menu: http://code.google.com/p/simple-pygame-menu/
simple popup window: How to specify what actually happens when Yes/No is clicked with ctypes MessageBoxW?