2012-12-17 5 views
0

아무도 내가 잘못하고있는 것을 알아낼 수 있습니까? GUI에 대한 경험이 거의 없습니다. 코드 :Python, wxPython 오류

import wx 
    class bucky(wx.Frame): 
      #constructor 
     def __init__(self,parent,id): 
      wx.Frame.__init__(self,parent,id,'Frame aka window',size=(300,200)) 
      panel=wx.Panel(self) 
      button=wx.Button(panel,label="exit",pos=(130,10),size=(60,60)) 
      self.Bind(wx.EVT_BUTTON, self.closebutton,button) 
      self.Bind(wx.EVT_CLOSE, self.closewindow) 
     def closebutton(self,event): 
      self.close(True) 
     def closewindow(self,event): 
      self.Destroy() 
    if __name__=='__main__': 
     app=wx.PySimpleApp() 
     frame=bucky(parent=None,id=-1) 
     frame.Show() 
     app.MainLoop() 

오류 :

PyNoAppError: The wx.App object must be created first! 

win32ui.error: Error in Command Message handler for command ID 36864, Code 0 
+2

코드의 들여 쓰기를 수정하여 텍스트 편집기에서 모든 모양이 들여 쓰기되도록하십시오. 파이썬에서는 매우 중요합니다. – Marius

+0

제 3의 인자가 필요 없다고 생각합니다. self.Bind (wx.EVT_BUTTON, self.closebutton, button)' –

+0

완전한 추적입니까? 그 오류가 어떤 줄에서 왔는지 알려주 죠? – Blair

답변

0

이 코드는 wxPython을 2.8.12.1 및 파이썬 2.6.6와 Windows 7에서 나를 위해 실행됩니다. 어떤 OS와 Python 버전을 사용하고 있습니까? IDLE에서 코드를 실행했을 때이 오류 메시지를 수시로 보았습니다. 네가 그렇게한다면, 하지마. Tkinter의 mainloop (IDLE이 만들어지는 것)은 다른 GUI 툴킷의 주요 루프를 방해합니다.

존재하지 않는 "닫기"메서드를 호출한다는 점에서 closebutton 메서드에 문제가 있습니다.

+0

답변 해 주셔서 감사합니다. PythonWin을 사용하고 있습니다. 2.7.3 – user1908907

+0

명령 줄에서 스크립트를 실행 해보십시오. –