Some questions on creating a GUI

I want to create a main menu for my game. I thought the built in GUI modules would work great, but I am having a problem doing something that is very simple in my old game engine (PyU3D):

I have created all my menu buttons in PS. They are simple “startup.png” and “startdown.png”. All I need to do is find out if the mouse is over the “startup” image, and if so change to the “startdown” image.

But I find there is no built in function to do this!?!

I tried using the built in buttons with an image overlay, but they add a crappy background to my images.

Oh, and how can I keep the screen from being resized?



This is very simple in Panda as well, although it probably could be more obvious :wink:.

The way I do it (and it probably isn’t the only way possible) is by using a DirectButton. To make it react to the mouse “hovering” over, I use this code:

myButton.bind(DGG.WITHIN, <my_callback_function>)

For hovering out it’s the same, but with DGG.WITHOUT.

Not sure why the name “within” and “without”… but this should do the trick and it works well for me.

Just make sure you have DirectGuiGlobals imported. That’s…

import direct.gui.DirectGui.DGG

As far as the “crappy background”, I suppose you mean the relief. I personally don’t like it too (even though it might be useful), so I just use this:

relief = DGG.FLAT

in my DirectButton definitions. That way I get a nice, flat button.

I hope this helps.


What do you mean?

Is there anyway I can remove the background all together?

If you click the maximize button, or the corner of the window and drag it the screen size changes. I don’t want this to happen.

as for your original question there is a roll-over state you can specify.

as for the screen resizeablitiy. you cant enforce it. in best case you can ask the OS to make the window non-resizeable. but there is no garantuee the OS will do what you request.

for general GUI stuff you may also want to investigate the egg-texture-cards tool. and maybe this link can help you a bit

Well, I don’t think you can remove it, since that’s the “area” of the button (where the button reacts to input), but you can always make it transparent.

Setting relief = None removes the background altogether, which is perfectly reasonable if you are supplying your own background card.

Note that a DirectButton automatically does the substitution you describe. You don’t have to bind any events on within and without it make it switch to the rollover state; that’s what a DirectButton does all by itself.

Edit: put:

win-fixed-size 1

in your Config.prc to request the OS to give you a non-resizeable window. As Thomas says, this is not a guarantee, but it will do the right thing in almost all cases.


Ah, didn’t know that. Handy.

Tried that here. The little marker in the bottom right corner of the window it gone, but you can still grab the window there and resize it :confused:

Oh, hmm, how about that. Looks like we’ve got something wrong in the OSX case.

Edit: fix committed.


Thank you all so much!

Everything is working perfectly now.