XRC and dynamically created widgets?
John Salerno
johnjsal at NOSPAMgmail.com
Mon Oct 2 11:16:55 PDT 2006
Robin Dunn wrote:
> If you define the pages in the XRC as children of the notebook then when
> you load the notebook it will load all the pages. If you want to load
> the pages separately, then define them in the XRC as separate top-level
> panels. Then in your code when you decide to add a page you can load it
> from the XRC at that time and add it to the notebook programatically.
I tried this but I think I must be doing it wrong. I defined a separate
Panel object at the top-level, and I tried adding it to the notebook.
Here is my code:
import wx
from wx import xrc
class MyApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource('gui.xrc')
self.frame = self.res.LoadFrame(None, 'mainFrame')
self.panel = xrc.XRCCTRL(self.frame, 'panel')
self.notebook = xrc.XRCCTRL(self.panel, 'notebook')
self.page = self.res.LoadPanel(self.notebook, 'page')
self.notebook.AddPage(self.page, 'Title')
self.frame.Show()
return True
if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()
And here is the XRC:
<?xml version="1.0" encoding="utf-8"?>
<resource>
<object class="wxFrame" name="mainFrame">
<title>Test Frame</title>
<object class="wxPanel" name="panel">
<object class="wxNotebook" name="notebook"/>
</object>
</object>
<object class="wxPanel" name="page"/>
</resource>
More information about the wxpython-users
mailing list