wxFormBuilder和框架子类

时间:2016-08-02 11:43:54

标签: python python-2.7 wxpython wxwidgets wxformbuilder

我一直在尝试使用wxFrameBuilder来创建框架的子类,这样我就可以调用继承了很多主框架的子类,但是通过替换面板来覆盖部分框架。 这是wxFormBuilder生成的测试代码。

    class MainMenu ( wx.Frame ):

    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
        self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVECAPTION ) )

        bSizer59 = wx.BoxSizer( wx.VERTICAL )

        self.m_panel53 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer60 = wx.BoxSizer( wx.HORIZONTAL )

        self.m_staticText18 = wx.StaticText( self.m_panel53, wx.ID_ANY, u"Menu Title", wx.DefaultPosition, wx.DefaultSize, 0 )
        self.m_staticText18.Wrap( -1 )
        self.m_staticText18.SetFont( wx.Font( 20, 70, 90, 90, False, wx.EmptyString ) )
        self.m_staticText18.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVECAPTION ) )

        bSizer60.Add( self.m_staticText18, 0, wx.ALL, 5 )


        self.m_panel53.SetSizer( bSizer60 )
        self.m_panel53.Layout()
        bSizer60.Fit( self.m_panel53 )
        bSizer59.Add( self.m_panel53, 1, wx.EXPAND |wx.ALL, 5 )

        self.m_panel55 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        bSizer61 = wx.BoxSizer( wx.HORIZONTAL )

        self.m_button22 = wx.Button( self.m_panel55, wx.ID_ANY, u"1", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer61.Add( self.m_button22, 0, wx.ALL, 5 )


        bSizer61.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )

        self.m_button23 = wx.Button( self.m_panel55, wx.ID_ANY, u"2", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer61.Add( self.m_button23, 0, wx.ALL, 5 )


        bSizer61.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )

        self.m_button24 = wx.Button( self.m_panel55, wx.ID_ANY, u"3", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer61.Add( self.m_button24, 0, wx.ALL, 5 )


        self.m_panel55.SetSizer( bSizer61 )
        self.m_panel55.Layout()
        bSizer61.Fit( self.m_panel55 )
        bSizer59.Add( self.m_panel55, 1, wx.EXPAND |wx.ALL, 5 )


        self.SetSizer( bSizer59 )
        self.Layout()

        self.Centre( wx.BOTH )

    def __del__( self ):
        pass


class SubMenu ( MainMenu ):

    def __init__( self, parent ):
        MainMenu.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

        self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )

        bSizer59 = wx.BoxSizer( wx.VERTICAL )

        self.m_panel55 = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
        self.m_panel55.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_ACTIVECAPTION ) )

        bSizer61 = wx.BoxSizer( wx.HORIZONTAL )

        self.m_button22 = wx.Button( self.m_panel55, wx.ID_ANY, u"one", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer61.Add( self.m_button22, 0, wx.ALL, 5 )


        bSizer61.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )

        self.m_button23 = wx.Button( self.m_panel55, wx.ID_ANY, u"two", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer61.Add( self.m_button23, 0, wx.ALL, 5 )


        bSizer61.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 )

        self.m_button24 = wx.Button( self.m_panel55, wx.ID_ANY, u"three", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer61.Add( self.m_button24, 0, wx.ALL, 5 )


        self.m_panel55.SetSizer( bSizer61 )
        self.m_panel55.Layout()
        bSizer61.Fit( self.m_panel55 )
        bSizer59.Add( self.m_panel55, 1, wx.EXPAND |wx.ALL, 5 )


        self.SetSizer( bSizer59 )
        self.Layout()

        self.Centre( wx.BOTH )

    def __del__( self ):
        pass

这是我用来显示帧的代码。

import wx
from gui import *


class TopMenu(MainMenu):
    def __init__(self, parent):
        MainMenu.__init__(self, parent)

class SecondMenu(SubMenu):
    def __init__(self, parent):
        SubMenu.__init__(self, parent)


if __name__ == '__main__':
    app = wx.App(0)
    frame = SecondMenu(None)
    frame.Centre()
    frame.Show()
    app.MainLoop()

显示TopMenu(MainMenu)工作正常,但如上所述调用SecondMenu(子菜单)类会产生以下错误。

MainMenu.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

TypeError: init ()得到了一个意外的关键字参数' id'

这是一个简化的重新创建的错误。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

MainMenu.__init__的定义如下:

def __init__( self, parent ):

但你这样称呼它:

MainMenu.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString,
                    pos = wx.DefaultPosition, size = wx.Size( 500,300 ),
                    style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

看到问题?