Python 类型错误:在方法'中;新的U形框架';,类型为'的预期参数2;int';

Python 类型错误:在方法'中;新的U形框架';,类型为'的预期参数2;int';,python,user-interface,window,wxpython,frame,Python,User Interface,Window,Wxpython,Frame,以下是完整的回溯: import wx class MainWindow(wx.Frame): def _init_ (self, parent, title): wx.Frame. __init__(self, parent, title=title, size=(200, 100)) self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) self.CreateStatusBar(

以下是完整的回溯:

import wx
class MainWindow(wx.Frame):
    def _init_ (self, parent, title):
        wx.Frame. __init__(self, parent, title=title, size=(200, 100))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.CreateStatusBar()

        #setting up the menu

        filemenu = wx.Menu()

        menuAbout = filemenu.Append(wx.ID_ABOUT, "About", "information about the use of this program")
        menuExit = filemenu.Append(wx.ID_EXIT, "Exit", "Exit this program")

        menuBar = wx.MenuBar()

        menuBar.Append(filemenu,"File")
        self.SetMenuBar(menuBar)
        self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
        self.Bind(wx.EVT_MENU, self.OnExit, menuExit)

        self.Show(True)

    def OnAbout(self,e):
        dlg = wx.MessageDialog(self, "A small text editor", "About sample     editor", wx.OK)
        dlg.ShowModal()
        dlg.Destroy()

    def OnExit(self,e):
        self.Close(True)
    app = wx.App(False)
    frame = MainWindow(None, "sample editor")
    app.MainLoop()
C:\Python27\python.exe“C:/Users/User/Google Drive/order/menubar.py”
回溯(最近一次呼叫最后一次):
文件“C:/Users/User/Google Drive/order/menubar.py”,第39行,
帧内=主窗口(无,“示例编辑器”)
文件“C:\Python27\lib\site packages\wx-3.0-msw\wx_windows.py”,第580行,
在init windows.Frame_swiginit中(self、windows.new_Frame(*args、**kwargs))
TypeError:在方法“new_Frame”中,应为“int”类型的参数2
进程已完成,退出代码为1
  • 检查
    \uuuu init\uuu
    方法名称的拼写。它只有1个下划线 而不是2
  • 检查
    wx.Frame.\uuuu init\uuuu
    行的拼写。它有过多的空间
  • 检查从行开始的缩进
    app=wx.app(False)
  • 之后,代码应如下所示:

    C:\Python27\python.exe "C:/Users/User/Google Drive/order/menubar.py" 
    Traceback (most recent call last): 
    File "C:/Users/User/Google Drive/order/menubar.py", line 39, 
        in <module> frame = MainWindow(None, "sample editor") 
    File "C:\Python27\lib\site-packages\wx-3.0-msw\wx_windows.py", line 580, 
        in init windows.Frame_swiginit(self,windows.new_Frame(*args, **kwargs)) 
    TypeError: in method 'new_Frame', expected argument 2 of type 'int' 
    Process finished with exit code 1 
    

    您能给我们看一下完整的回溯吗?从文档中,参数是
    \uuuu init\uuuuu(self、parent、id、title、pos、size、style、name)
    。您已将
    parent
    作为第二个参数发送,此时它应该是一个id(类型为
    int
    )。您是否真的得到了两边各有一个下划线的init?将注释移动到编辑位置。
    import wx
    class MainWindow(wx.Frame):
        def __init__ (self, parent, title):
            wx.Frame.__init__(self, parent, title=title, size=(200, 100))
            self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
            self.CreateStatusBar()
    
            #setting up the menu
    
            filemenu = wx.Menu()
    
            menuAbout = filemenu.Append(wx.ID_ABOUT, "About", "information about the use of this program")
            menuExit = filemenu.Append(wx.ID_EXIT, "Exit", "Exit this program")
    
            menuBar = wx.MenuBar()
    
            menuBar.Append(filemenu,"File")
            self.SetMenuBar(menuBar)
            self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
            self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
    
            self.Show(True)
    
        def OnAbout(self,e):
            dlg = wx.MessageDialog(self, "A small text editor", "About sample     editor", wx.OK)
            dlg.ShowModal()
            dlg.Destroy()
    
        def OnExit(self,e):
            self.Close(True)
    
    app = wx.App(False)
    frame = MainWindow(None, "sample editor")
    app.MainLoop()