DirectButton parenting issue

You forgot about the hierarchical relationship, the a2dRightCenter node was created in advance. Accordingly, he got the order in the rendering, first you need to make the frame his child. There is no mistake here, the misunderstanding lies in the very presence of positional useless nodes, what the author of this code was counting on in base is not clear.

from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectGui import DirectFrame, DirectButton, DGG

class Game(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        
        #frameAlpha = 1   # Makes the button "disappear"
        frameAlpha = 0.5  # Makes the button partially visible

        self.background = DirectFrame(frameSize=(-2048, 2048, -2048, 2048), frameColor=(.25, .25, .25, frameAlpha))
        
        self.button = DirectButton(self.a2dRightCenter, text=("center",), scale=.07, pos=(-.25, 0, 0)) 

        render2d.ls()

app = Game()
app.run()
PandaNode render2d S:(CullFaceAttrib DepthTestAttrib DepthWriteAttrib MaterialAttrib)
  PGTop aspect2d T:(scale 0.75 1 1) S:(CullBinAttrib)
    PandaNode a2dBackground
    PandaNode a2dTopCenter T:(pos 0 0 1)
    PandaNode a2dTopCenterNS T:(pos 0 0 1)
    PandaNode a2dBottomCenter T:(pos 0 0 -1)
    PandaNode a2dBottomCenterNS T:(pos 0 0 -1)
    PandaNode a2dLeftCenter T:(pos -1.33333 0 0)
    PandaNode a2dLeftCenterNS T:(pos -1.33333 0 0)
    PandaNode a2dRightCenter T:(pos 1.33333 0 0)
      PGButton DirectButton-pg1 T:(pos -0.25 0 0 scale 0.07)
    PandaNode a2dRightCenterNS T:(pos 1.33333 0 0)
    PandaNode a2dTopLeft T:(pos -1.33333 0 1)
    PandaNode a2dTopLeftNS T:(pos -1.33333 0 1)
    PandaNode a2dTopRight T:(pos 1.33333 0 1)
    PandaNode a2dTopRightNS T:(pos 1.33333 0 1)
    PandaNode a2dBottomLeft T:(pos -1.33333 0 -1)
    PandaNode a2dBottomLeftNS T:(pos -1.33333 0 -1)
    PandaNode a2dBottomRight T:(pos 1.33333 0 -1)
    PandaNode a2dBottomRightNS T:(pos 1.33333 0 -1)
    PGItem DirectFrame-pg0
  PGTop pixel2d T:(pos -1 0 1 scale 0.0025 1 0.00333333) S:(CullBinAttrib)
  PandaNode camera2d
    Camera cam2d ( OrthographicLens )
      OrthographicLens film size = 2 2

Since the last added node will be on top.

Ah, you are of course correct! I’d overlooked just where ā€œa2dRightCenterā€ came from, and thus how it factored into precedence!

Well, thank you for the correction there! :slight_smile:

I can’t speak for the developer who made the positional nodes, but for what it’s worth I’ve found them to be occasionally useful for GUI-layouts. Especially in those cases in which I’ve wanted a GUI-element to remain near a window-edge, even when the window is resized.