我一直在尝试使用 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(Submenu) 类会出现以下错误。
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'
这是一个简化的重新创建错误。任何人都可以帮忙吗?