Hi all!
I need dynamically add and remove some widgets in my application,
it will add finally, but at first, it temporarily *flashes * to the top left corner about 1s.
This square vanishes almost immediately, but it’s clearly visible everytime you add widget.
It’s pretty ugly. I just can’t get rid of it!
Can’t work out why it would appear and then disappear! Is it a programme delay that I can’t get rid of?
Or some error I’m making with my sizers?
Here is my code, thanks!
import wx
···
########################################################################
class MyPanel(wx.Panel):
“”""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.number_of_buttons = 0
self.frame = parent
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
controlSizer = wx.BoxSizer(wx.HORIZONTAL)
self.widgetSizer = wx.BoxSizer(wx.VERTICAL)
self.addButton = wx.Button(self, label="Add")
self.addButton.Bind(wx.EVT_BUTTON, self.onAddWidget)
controlSizer.Add(self.addButton, 0, wx.CENTER|wx.ALL, 5)
self.mainSizer.Add(controlSizer, 0, wx.CENTER)
self.mainSizer.Add(self.widgetSizer, 0, wx.CENTER|wx.ALL, 10)
self.SetSizer(self.mainSizer)
#----------------------------------------------------------------------
def onAddWidget(self, event):
""""""
self.vcbox = wx.FlexGridSizer(3, 2, 5, 10)
label = wx.StaticText(self, -1, 'verifycode')
self.vcbox.Add(label, 0, wx.ALIGN_RIGHT| wx.LEFT, 40)
text = wx.TextCtrl(self, -1, style = 0)
self.vcbox.Add(text,1, wx.ALIGN_CENTER_HORIZONTAL| wx.RIGHT ,40)
tip = wx.StaticText(self, -1, 'some tipsssssss')
font = wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
tip.SetFont(font)
tip.SetForegroundColour('grey')
imbox = wx.BoxSizer(wx.HORIZONTAL)
image = wx.StaticBitmap(self, -1, )
imageTip = wx.StaticText(self, -1, 'some tipsssss')
imageTip.SetFont(font)
imageTip.SetForegroundColour('#889DB6')
imbox.Add(image, 0)
imbox.Add(imageTip, 0, wx.ALIGN_BOTTOM)
imbox.Layout()
self.frame.Fit()
self.vcbox.Add(wx.StaticText(self, -1), 0)
self.vcbox.Add(tip, 1)
self.vcbox.Add(wx.StaticText(self, -1), 0)
self.vcbox.Add(imbox, 1)
self.widgetSizer.Add(self.vcbox, 0, wx.ALL, 5)
self.frame.fSizer.Layout()
self.frame.Fit()
#----------------------------------------------------------------------
def onRemoveWidget(self, event):
""""""
pass
########################################################################
class MyFrame(wx.Frame):
“”""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="Add / Remove Buttons")
self.fSizer = wx.BoxSizer(wx.VERTICAL)
panel = MyPanel(self)
self.fSizer.Add(panel, 1, wx.EXPAND)
self.SetSizer(self.fSizer)
self.Fit()
self.Show()
#----------------------------------------------------------------------
if name == “main”:
app = wx.App(False)
frame = MyFrame()
app.MainLoop()