How to place my GUI elements in correct position conveniencely

I’m working for a design of GUI by panda3d now.
But one thing is troubled that I use setPos to place my GUI in the window, but it’s difficult to determine the proper parameters. So I try lots of different parameters of setPos, and adjust them after running the program to see the actual effort. For example, I have a Entry and I set its pos as (1,0,1), then I run the program but I find it is on the left side of the desired position, so I need to change it to (0.9,0,1)…again and agian.

I think it’s not a good way to adjust the elements’ position,
so if there any more convenience way?

The third paragraph of this manual page describes a direct-gui-edit option that I think is what you’re looking for:

The direct-gui-edit option in the Config.prc file allows the user to use the middle mouse button to move around widgets, and resize them while holding the control key; this is very useful to lay a screen out during development. If you need to turn this ability off for an individual object, set its enableEdit keyword parameter to False.

However, I do not know if there is a convenient way to get the position values after you’ve adjusted the widgets.

That’s really neat–I wasn’t aware of this! :slight_smile:

As to getting the position-values, if there’s no more-convenient method, then simply printing them out in an event bound to a key-press should work.

Also, if you wish to place elements relative to a particular corner or edge of the window, you should parent them to one of the following nodes instead of base.aspect2d:

base.a2dTopLeft
base.a2dTopRight
base.a2dBottomLeft
base.a2dBottomRight
base.a2dTopCenter
base.a2dBottomCenter
base.a2dLeftCenter
base.a2dRightCenter

Thank you for all your advice, however, my default direct-gui-edit option in the Config.prc file is false, how can I change it to true in my program (rather than edit it in the prc file)
I use ConfigVariableString(“direct-gui-edit”) to get the value, but it seems setValue(1) can’t work

You can use panda3d.core.load_prc_file_data():

from panda3d.core import load_prc_file_data
load_prc_file_data('', 'direct-gui-edit #t')

For those of you having trouble with this, beware that you have to make that load_prc_file_data call BEFORE importing from direct.gui.DirectGui or it will not work!
So at the top of your code, you should have something like this:

from panda3d.core import load_prc_file_data
load_prc_file_data('', 'direct-gui-edit #t')
from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectGui import DirectFrame, DirectButton

In the direct/gui/DirectGuiBase.py file of the codebase I see there is a printConfig method bound to DGG.PRINT to print out the position and scale values to the console, but I’m not entirely sure what DGG.PRINT refers to - I tried pressing PrintScreen on the keyboard, but it doesn’t seem to work.

thank you very much!

Thank you for your help!