Prevent wx.Frame from resizing when overlaying wx.Panel buttons?

Ok, embarrassingly I think I can answer my own question...

I overlooked this:

hsizer.AddSpacer((435,0))

My bad. It's obvious that the spacer forced the frame to expand as I added
another button. I've reduced the spacer amount to correct it.

Still wondering though, I only used spacers because I could right align these
buttons properly by just using sizer properties - is there a better way to
accomplish this to maintain platform independence?

···

From: David LePage <dwlepage@yahoo.com>
Date: 2011/4/9
Subject: Re: [wxPython-users] Prevent wx.Frame from resizing when
overlaying wx.Panel buttons?
To: wxpython-users@googlegroups.com

----- Original Message ----
From: David LePage <dwlepage@yahoo.com>
To: wxpython-users@googlegroups.com
Sent: Fri, April 8, 2011 2:47:52 PM
Subject: [wxPython-users] Prevent wx.Frame from resizing when overlaying
wx.Panel buttons?

Hi,
I've been stumped on this one for quite some time.

I have a wx.Frame and a "base" panel that contains wx.Buttons to navigate
through the application (next, back, cancel).
When I display the Next and Cancel buttons, the frame is reasonably sized to my
liking.
However, when I add the "Back" button, the frame stretches width wise,
presumably to make room for the wx.Button that I just added.
If I hide the Back button, the frame shrinks back to a reasonable size.

Could someone suggest a way to make my frame static in size and allow the
wx.Buttons to adjust their position to fit inside of the frame? I dont want the
frame to stretch out as it makes the UI look disproportionate.

I've attached same code here that displays what I mean:

...

If you run this, then uncomment: "#hrt_sizer.Hide(back, recursive=True)" you
will see the frame size go down in width.

thanks for the help,

david

--

Hi,
you can probably group the right-aligned buttons in an inner
horizontal sizer and align it as as you do now. However, the size of
the whole dialog would have to be maintained (or, rather hackish, you
can swap whe unneded button wit a spacer aof the same size).
mayboe comething linke:
   back_bt_size = back.GetSizeTuple()
   hrt_sizer.Hide(back, recursive=True)
   hrt_sizer.Insert(0, back_bt_size, wx.ALL, 5)
   self.SetSizerAndFit(vsizer)
(however, probably some borders must be tweaked, as the sizes aren't
identical, now).

Anyway, what about just using Disable() on the unneeded button?
I guess, this is rather usual in wizards

back.Disable()

hth,
  vbr

It seems that you are thinking about the the Frame resizing issue in a difficult way. Why would you want to resize the Frame at all ? Why don’t you set the Frame, or better yet, the Frame.ClientSize to a fixed size to begin ? Then, when buttons are added or removed ( .Show() / .Hide() ) the button’s sizer will adjust their positions. It can be very annoying to the user’s eyes for the Frame to resize just be adding or removing things like Buttons unless there’s a specific and important reason to do so.

Ray Pasco