XRC and dynamically created widgets?
John Salerno
johnjsal at NOSPAMgmail.com
Mon Oct 2 12:19:46 PDT 2006
John Salerno wrote:
> Ah, I forgot to add the Notebook to a BoxSizer! Now it works! :)
Ok, more confusion. Here is my code and XRC. Why do I get this error
message when I don't comment out the two lines in the InitMenu() method,
but when they are commented it works fine (and still shows the menu bar)?
Python Error
XRC resource 'menuBar' (class 'wxMenuBar') not found!
-------------------
import wx
from wx import xrc
class DBApp(wx.App):
def OnInit(self):
self.res = xrc.XmlResource('dbgui.xrc')
self.InitFrame()
self.InitMenu()
self.frame.Show()
return True
def InitFrame(self):
self.frame = self.res.LoadFrame(None, 'mainFrame')
self.panel = xrc.XRCCTRL(self.frame, 'panel')
self.notebook = xrc.XRCCTRL(self.panel, 'notebook')
def InitMenu(self):
#self.menubar = self.res.LoadMenuBar('menuBar')
self.frame.Bind(wx.EVT_MENU, self.OnNewPage,
id=xrc.XRCID('newRecordMenuItem'))
#self.frame.SetMenuBar(self.menubar)
def OnNewPage(self, evt):
self.page = self.res.LoadPanel(self.notebook, 'dataPage')
self.notebook.AddPage(self.page, 'Title')
if __name__ == '__main__':
app = DBApp(False)
app.MainLoop()
--------------------------
<?xml version="1.0" encoding="utf-8"?>
<resource>
<object class="wxFrame" name="mainFrame">
<title>Database Access Form</title>
<object class="wxMenuBar" name="menuBar">
<object class="wxMenu" name="fileMenu">
<label>File</label>
<object class="wxMenuItem" name="newRecordMenuItem">
<label>New Record</label>
<help>Create a new record in open database</help>
</object>
</object>
</object>
<object class="wxPanel" name="panel">
<object class="wxBoxSizer">
<orient>wxHORIZONTAL</orient>
<object class="sizeritem">
<object class="wxNotebook" name="notebook"/>
<option>1</option>
<flag>wxEXPAND</flag>
</object>
</object>
</object>
<object class="wxStatusBar" name="statusBar"/>
</object>
<object class="wxPanel" name="dataPage"/>
</resource>
More information about the wxpython-users
mailing list