12

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.

Community
  • 1
  • 1
nmichaels
  • 49,466
  • 12
  • 107
  • 135

6 Answers6

2

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:

  1. Get the mouse position
  2. Is the mouse over any of the buttons (and no buttons are pressed)?
  3. Display hover image
  4. Is the mouse over a button and a mouse button is clicked?
  5. Fire event associated with that button
  6. 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)

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • This is what I was trying to avoid. I'd rather take an existing library like pgu (which is LGPL licenced) and update it. It's 40 source files (not counting documentation) and about 7,000 lines of Python code. – nmichaels Jul 27 '10 at 13:02
  • That's also possible - I've never used pgu so I have no clue how advanced it is - but if it already does a lot of the initial work, you have every reason to go ahead and update that. Assuming those 7,000 lines are good lines, anyway ;) – Wayne Werner Jul 27 '10 at 13:28
  • Yeah, I'm thinking I may just do that, assuming StackOverflow doesn't add any magic data to the equation. – nmichaels Jul 27 '10 at 18:05
  • However, pgu is not just GUI. It also has (IIRC) 3 different tile engines and some other utilies. So not all those lines are GUI. – PrettyPrincessKitty FS Jan 04 '11 at 17:00
2

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

milleja46
  • 21
  • 1
  • I disagree. I was referred to this SO question from here: https://stackoverflow.com/questions/8291274/is-there-anything-i-need-aware-of-using-tkinter-and-pygame-together/8291303#8291303 where one of the answers demonstrates that you can embed TKinter objects into a pygame interface easily. – Marc Maxmeister Aug 26 '19 at 18:12
1

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.

Community
  • 1
  • 1
Dave Burton
  • 2,960
  • 29
  • 19
1

Albow from the python wiki http://wiki.python.org/moin/PythonGameLibraries

0

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.

  • this is the simplest way to make clickable images on the screen, but it becomes tedious if you want your game to have a full menu bar of options and resemble the OS interface. – Marc Maxmeister Aug 26 '19 at 18:13
0

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?

Community
  • 1
  • 1