Ignore the previous post.
I am trying to understand some Statusbar behavior.
In the below code, if I click" Destroy Statusbar" followed by “Create Statusbar”, my code works as expected.
If I click “Destroy Statusbar” twice in a row, my program abruptly exits. The exception block does not catch any errors.
If I click "Create Statusbar twice in a row, my program reports the following error message.
wx._core.wxAssertionError: C++ assertion “!m_frameStatusBar” failed at …\src\common \framecmn.cpp(381) in wxFrameBase::CreateStatusBar(): recreating status bar in wxFrame
I am using wxPython 4.0.7 post 2, Python 3.6.5, Win 10
Any idea how to fix the above?
Thanks,
Bruce
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='Statusbar testing')
panel = wx.Panel(self)
destroyStatusbar = wx.Button(panel, label='Destroy StatusBar')
destroyStatusbar.Bind(wx.EVT_BUTTON, self.destroySB)
createStatusbar = wx.Button(panel, label='Create StatusBar')
createStatusbar.Bind(wx.EVT_BUTTON, self.createSB)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(destroyStatusbar, 0, wx.ALL, 20)
sizer.Add(createStatusbar, 0, wx.ALL, 20)
panel.SetSizer(sizer)
self.statusbar = self.CreateStatusBar(2)
self.statusbar.SetStatusText('111111')
self.statusbar.SetStatusText('222222', 1)
self.Show()
def destroySB(self, event):
print ("Trying to destroy Statusbar")
try:
self.statusbar.Destroy()
print ("Statusbar destroyed")
except:
print ("Unable to destory Statusbar")
def createSB(self, event):
print ("Trying to create Statusbar")
try:
self.statusbar = self.CreateStatusBar(2)
self.statusbar.SetStatusText('111111AAAA')
self.statusbar.SetStatusText('222222AAAA', 1)
print ("Statusbar created")
except:
print ("Unable to create Statusbar")
if __name__ == '__main__':
app = wx.App(False)
frame = TestFrame()
app.MainLoop()