你需要这样称呼它:
res = wx.xrc.EmptyXmlResource() #Here it is
res.LoadFromString(resourceText)
这是一个例子。
import wx, wx.xrc
resourceText = '''<?xml version="1.0" encoding="UTF-8"?>
<resource>
<object class="wxPanel" name="MyPanel">
<object class="wxStaticText">
<size>80,-1</size>
<label>Hey</label>
</object>
</object>
</resource>
'''
class TestFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, 'Testing',
size=(640,480))
res = wx.xrc.EmptyXmlResource() #Here it is
res.LoadFromString(resourceText)
panel = res.LoadPanel(self, "MyPanel")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panel, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
self.SetAutoLayout(True)
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = TestFrame(None)
frame.Show(True)
app.MainLoop()