我正在尝试使用Notebook类在wxPython中制作选项卡。根据上面链接的教程,我编写了以下代码:
#!/usr/bin/env python
import wx
class DeployTab(wx.Panel):
def __init__(self, parent, *args, **kwargs):
super(DeployTab, self).__init__(self, *args, parent=parent, id=wx.ID_ANY, **kwargs)
self.sizer = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.VERTICAL)
deploy = wx.Button(
self.main_panel,
label="test 1",
size=(250, 100))
self.sizer.Add(deploy, flag=wx.EXPAND|wx.ALL, border=5)
self.SetSizer(self.sizer)
class ConfigTab(wx.Panel):
# For now, copy.
def __init__(self, parent, *args, **kwargs):
super(ConfigTab, self).__init__(self, *args, parent=parent, id=wx.ID_ANY, **kwargs)
self.sizer = wx.Panel(self)
self.sizer = wx.BoxSizer(wx.VERTICAL)
deploy = wx.Button(
self.main_panel,
label="test2",
size=(250, 100))
self.sizer.Add(deploy, flag=wx.EXPAND|wx.ALL, border=5)
self.SetSizer(self.sizer)
class NotebookTabs(wx.Notebook):
def __init__(self, parent):
super(NotebookTabs, self).__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT)
self.deploy_tab = DeployTab(self)
self.deploy_tab.SetBackgroundColor("Gray")
self.AddPage(self.main_tab, "Go!")
self.options_tab = ConfigTab(self)
self.AddPage(self.options_tab, "Options")
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.SetSize((300, 250))
self.SetTitle('Testing')
self.Centre()
self.Show(True)
self.setup_sizers()
def setup_sizers(self):
self.panel = wx.Panel(self)
self.notebook = NotebookTabs(self.panel)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.notebook, 1, wx.ALL|wx.EXPAND, 5)
self.panel.SetSizer(self.sizer)
self.Layout()
def on_quit(self, event):
self.Close()
def main():
app = wx.App()
MainWindow(None)
app.MainLoop()
if __name__ == '__main__':
main()
它会显示以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.pyw", line 72, in main
MainWindow(None)
File "test.pyw", line 55, in __init__
self.setup_sizers()
File "test.pyw", line 61, in setup_sizers
self.notebook = NotebookTabs(self.panel)
File "test.pyw", line 36, in __init__
super(NotebookTabs, self).__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 3147, in __init__
_controls_.Notebook_swiginit(self,_controls_.new_Notebook(*args, **kwargs))
TypeError: Argument given by name ('id') and position (2)
然后我将NotebookTabs
更改为以下内容(简化超类初始化):
class NotebookTabs(wx.Notebook):
def __init__(self, parent):
super(NotebookTabs, self).__init__(self, parent)
self.deploy_tab = DeployTab(self)
self.deploy_tab.SetBackgroundColor("Gray")
self.AddPage(self.main_tab, "Go!")
self.options_tab = ConfigTab(self)
self.AddPage(self.options_tab, "Options")
...并收到了以下错误信息:
File "<stdin>", line 1, in <module>
File "test.pyw", line 72, in main
MainWindow(None)
File "test.pyw", line 55, in __init__
self.setup_sizers()
File "test.pyw", line 61, in setup_sizers
self.notebook = NotebookTabs(self.panel)
File "test.pyw", line 36, in __init__
super(NotebookTabs, self).__init__(self, parent)
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_controls.py", line 3147, in __init__
_controls_.Notebook_swiginit(self,_controls_.new_Notebook(*args, **kwargs))
TypeError: in method 'new_Notebook', expected argument 1 of type 'wxWindows *'
我感觉好像漏了什么很明显的东西,但似乎无法确定问题出在哪里。有人可以帮我识别问题吗?