Here is a simple wxPython app:
import wx app = wx.App(False) frame = wx.Frame(None, title='Hide/Show bug', size=(400,600)) framesizer = wx.BoxSizer(); frame.SetSizer(framesizer) panel = wx.Panel(frame) panelsizer = wx.BoxSizer(orient=wx.VERTICAL) panel.SetSizer(panelsizer) framesizer.Add(panel, 1, wx.EXPAND) heading = wx.StaticText(panel, label="heading") panelsizer.Add(heading, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=12) button = wx.Button(panel, label="Show the gauge") progress = wx.Gauge(panel, style=wx.GA_HORIZONTAL | wx.GA_SMOOTH | wx.GA_PROGRESS) panelsizer.Add(button, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, border=12) panelsizer.Add(progress, 0, wx.EXPAND | wx.ALL, border=12) button.Bind(wx.EVT_BUTTON, lambda e, progress=progress: progress.Show()) #progress.Hide() frame.Show(); app.MainLoop()
If you run this (on Linux but Mac seems to have the same issue), you get the same sort of correct view, with a simple panel with a button and a Gauge:
but! if I add back in the progress.Hide() line, which is currently commented out, and then press the button to show the Gauge at runtime, it looks like this:
that is: the Gauge now appears unaligned at the top of the window, rather than appearing in the correct place.
What am I doing wrong here? Is it not OK to hide and show elements in a sizer? Should I be doing something else instead to hide the progress bar and then make it appear on command?