Wxpython Panel In Existing Window: Slow And Small
I'm experiencing very different behavior when creating a wx.Panel depending on whether the main window's already called Show(). With the below code, the application opens quickly w
Solution 1:
The panel will get the correct size if the Frame feels a SizeEvent. So this works for your second question:
defOnNew(self, evt):
ifself.panel:self.panel.Destroy()
self.panel = MainPanel(self)
self.SendSizeEvent()
Control of windows and widgets becomes easier by using sizers. With sizers in your main frame you can use the sizer Layout
method to fit widgets in place.
Could not find a way of speeding up panel rewrite. But you can diminish the bizarre visual effect by not deleting the panel but clearing the sizer instead (you dont need SendSizeEvent()
for this case):
classMainPanel(wx.lib.scrolledpanel.ScrolledPanel):
def__init__(self,parent):
wx.lib.scrolledpanel.ScrolledPanel.__init__(self, parent=parent)
self.SetupScrolling()
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.fill()
self.SetSizer(self.sizer)
deffill(self):
tup = [wx.StaticText(self, wx.ID_ANY, "I'm static text") for i inrange(200)]
self.sizer.AddMany(tup)
self.Layout()
classMainFrame(wx.Frame):
def__init__(self):
wx.Frame.__init__(self, None, title="FrameTest", size=(600,800))
self.InitMenu()
self.panel = None
self.panel = MainPanel(self)
defInitMenu(self):
self.menuBar = wx.MenuBar()
menuFile = wx.Menu()
menuFile.Append(wx.ID_NEW, "&New")
self.Bind(wx.EVT_MENU, self.OnNew, id=wx.ID_NEW)
self.menuBar.Append(menuFile, "&File")
self.SetMenuBar(self.menuBar)
defOnNew(self, evt):
if self.panel:
self.panel.sizer.Clear()
self.panel.fill()
Post a Comment for "Wxpython Panel In Existing Window: Slow And Small"