2015-05-29 91 views
0
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() 

以下是完整的回溯的預期論點2:類型錯誤:在方法 '新幀',類型 '詮釋'

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 
+1

你能告訴我們充分回溯? – Scironic

+0

從['wx.Frame'](http://www.wxpython.org/docs/api/wx.Frame-class.html)的文檔中,參數是__init __(self,parent,id,title,pos ,大小,樣式,名稱)'。當它應該是一個id(類型爲「int」)時,你已經發送了'parent'作爲第二個參數。 – 101

+0

你真的得到了_init_每邊都有一個下劃線嗎? –

回答

0
  1. 檢查的__init__方法名拼寫。它只有一個下劃線 而不是2
  2. 檢查拼寫wx.Frame.__init__一行。是有多餘的間隙
  3. 檢查從壓痕線app = wx.App(False)

開始,你的代碼後應該如下所示:

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() 
+0

非常感謝Vader –

相關問題