2012-05-16 84 views
-1

有人可以看看這個代碼有什麼問題..一切看起來不錯,但我得到縮進錯誤。縮進錯誤-Python幀

下面的代碼創建一個新的框架,幷包含一個按鈕。當單擊該按鈕是一個事件被觸發,顯示有關父母和孩子更多的信息.​​.

代碼:

import wx 
class MyApp(wx.App): 
    def OnInit(self): 
     self.frame = MyFrame(None, title="The Main Frame") 
     self.SetTopWindow(self.frame) 
     self.frame.Show() 
     return True 

class MyFrame(wx.Frame): 
    def __init__(self, parent, id=wx.ID_ANY, title="", 
       pos=wx.DefaultPosition, size=wx.DefaultSize, 
       style=wx.DEFAULT_FRAME_STYLE, 
       name="MyFrame"): 
     super(MyFrame, self).__init__(parent, id, title, 
             pos, size, style, name) 
     # Attributes 
     self.panel = wx.Panel(self) 
     self.panel.SetBackgroundColour(wx.BLACK) 
     self.button = wx.Button(self.panel, 
           label="Push Me", 
           pos=(50, 50)) 
     self.btnId = button.GetId() 
     # Event Handlers 
     self.Bind(wx.EVT_BUTTON, self.OnButton, button) 

    def OnButton(self, event): 
     """Called when the Button is clicked""" 
     print "\nFrame GetChildren:" 
     for child in self.GetChildren(): 
      print "%s" % repr(child) 
     print "\nPanel FindWindowById:" 
     button = self.panel.FindWindowById(self.btnId) 
     print "%s" % repr(button) 
     # Change the Button's label 
     button.SetLabel("Changed Label") 
     print "\nButton GetParent:" 
     panel = button.GetParent() 
     print "%s" % repr(panel) 
     print "\nGet the Application Object:" 
     app = wx.GetApp() 
     print "%s" % repr(app) 
     print "\nGet the Frame from the App:" 
     frame = app.GetTopWindow() 
     print "%s" % repr(frame) 

if __name__ == "__main__": 
    app = MyApp(False) 
    app.MainLoop() 

以下是錯誤:

C:\Python27\wx>python frame_new.py 
    File "frame_new.py", line 22 
    self.btnId = button.GetId() 
    ^
IndentationError: unexpected indent       

回答

2

打開某些程序,可以顯示製表符和空格,如記事本++ Windows上的文件。然後你可以看到你是否有某種標籤/空間混合或某種東西。