'How do I get a wx.Dialog in Python to shrink to "just big enough"?

I am putting together a WxPython Phoenix application, using wxFormBuilder to do the GUI.

I have a wxDialog, with an wxBoxSizer (stacking vertically) inside it. Inside that, I have a wxFlexGridSizer above (for data entry), a wxStaticLine, and a wxBoxSizer (with OK/CANCEL buttons).

The wxFlexGridSizer has 2 columns, the first with field labels and the 2nd with text entry fields.

I have everything pretty, but sometimes I don't need some of the data entry fields, so I Hide() them (and their corresponding labels). They don't show up then (which is what I want), but I can't figure out how to get the wxDialog to resize to "just big" enough after that; it remains at the original size. The wxFlexGridSizer is resizing, but the wxDialog is remaining the same size (with extra white space at the bottom).

What do I need to do to get this to work right? I have tried every combination of Layout() and Fit() that I can think of...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source