0

我使用 wxFormBuilder 在 python 代码中生成我的 ui 和 xrc 文件,我所做的是:

self.res = xrc.XmlResource("abcd_xrc.xrc")
self.frame = self.res.LoadFrame(None, 'MyFrame2')
self.frame.SetSize((750,700))

我加载 xrc 文件然后加载框架最后我想在这里更改框架大小 self.frame 对象是 None

错误是:

    Traceback (most recent call last):
  File "D:\ODN-NMM-Python\realease\Test_Cons.py", line 191, in <module>
    app = MyApp(0)
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8628, in __init__
    self._BootstrapApp()
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8196, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "D:\ODN-NMM-Python\realease\Test_Cons.py", line 40, in OnInit
    self.Init_frame()
  File "D:\ODN-NMM-Python\realease\Test_Cons.py", line 50, in Init_frame
    self.frame.SetSize((750,700))
AttributeError: 'NoneType' object has no attribute 'SetSize'

我的 xrc 文件的一些内容是:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<resource xmlns="http://www.wxwindows.org/wxxrc" version="2.3.0.1">
    <object class="wxFrame" name="MyFrame2">
        <style>wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL</style>
        <size>500,300</size>
        <title></title>
        <centered>1</centered>
        <aui_managed>0</aui_managed>
        <object class="wxBoxSizer">
            <orient>wxVERTICAL</orient>
            <object class="sizeritem">
                <option>1</option>
                <flag>wxEXPAND</flag>
                <border>5</border>
                <object class="wxBoxSizer">
                    <orient>wxHORIZONTAL</orient>
                    <object class="sizeritem">
                        <option>2</option>
                        <flag>wxEXPAND | wxALL</flag>
                        <border>5</border>

我的 xrc 框架的名称正是“MyFrame2”但是当我加载它时,显然返回对象是错误的,所以发生了错误。

4

0 回答 0