wxPython: Updating the label on wxStatic causes text to be incorrectly formated
I have a form that uses wxpython, one of the objects on the form displays the users windows logon name.
self.stIwpcadmin = wx.StaticText(self.panelLower, -1, "NONE")
Of course I don't know what the name is until runtime so I create a wxStatic object with the label of 'NONE', and then at runtime it gets the username and changes the label
sUsername = getpass.getuser()
self.stIwpcadmin.SetLabel('WINDOWS/'+sUsername)
When this occurs it does update the text of the wxStatic object. The problem is that it 'runs' into the next object in the GridSizer. If I adjust the size of the window (any amount, larger or smaller) it forces the object to redraw and it fills in the text correctly.
How can I force this to occur with needing the user to change the window size?
This is the code that shows the sizer data for wxStatic info. I cut some code out to keep it as brief as possible. In short self.stIwpcadmin -> grid_sizer_1 -> sizerPassword -> sizerLower -> self.panelLower -> mainSizer
def __do_layout(self):
# begin wxGlade: mainFrame.__do_layout
mainSizer = wx.GridSizer(2, 1, 0, 0)
sizerLower = wx.GridSizer(1, 2, 0, 0)
sizerInstall = wx.StaticBoxSizer(self.sizerInstall_staticbox, wx.HORIZONTAL)
sizerInstallButtons = wx.GridSizer(1, 2, 0, 0)
sizer_4 = wx.BoxSizer(wx.VERTICAL)
sizerPassword = wx.StaticBoxSizer(self.sizerPassword_staticbox, wx.HORIZONTAL)
grid_sizer_1 = wx.GridSizer(8, 3, 0, 0)
mainSizer.Add(self.panelUpper, 1, wx.EXPAND, 0)
grid_sizer_1.Add(self.stIwpcadmin, 0, wx.ALL|wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 2)
grid_sizer_1.Add(self.txIwpcadmin, 0, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL, 2)
grid_sizer_1.Add(self.btnIwpcadmin, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 2)
grid_sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
grid_sizer_1.Add(self.panel_2, 1, wx.EXPAND, 0)
grid_sizer_1.Add(self.btnValidateAll, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 2)
sizerPassword.Add(grid_sizer_1, 1, wx.EXPAND, 0)
sizerLower.Add(sizerPassword, 1, wx.EXPAND, 0)
self.panelLower.SetSizer(sizerLower)
mainSizer.Add(self.panelLower, 1, wx.EXPAND, 0)
self.SetSizer(mainSizer)
mainSizer.F开发者_高级运维it(self)
self.Layout()
You need to force the sizer to redo its layout using the aptly-named Layout method.
精彩评论