2012-05-16 86 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上的文件。然后你可以看到你是否有某种标签/空间混合或某种东西。