有人可以看看这个代码有什么问题。对我来说一切都很好但我得到缩进错误。
下面的代码会创建一个新框架并包含一个按钮。单击该按钮时会触发一个事件并显示有关父母和子女的更多信息。
代码:
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
答案 0 :(得分:2)
在某些可以显示标签和空格的程序中打开文件,例如Windows上的Notepad ++。然后你可以看看你是否有某种标签/空格混合物。