我在下面的代码中遇到“预期的缩进块”错误:我是python的新手请帮忙
#!/bin/env python
import wx
class MyFrame(wx.Frame):
def __init(self):
wx.Frame.__init__(self, None, -1,"My Frame", size=(300,300))
panel = wx.Panel(self, -1)
panel.Bind(wx.EVT_MOTION, self.OnMove)
wx.StaticText(panel,-1,"POS:",pos=(10, 12))
self.PosCtrl = wx.TextCtrl(panel, -1,"",pos=(40, 10))
def OnMove(self, event):
pos = event.GetPosition()
Self.PosCtrl.SetValue("%s, %s" % (pos.x,pos.y))
if __name__ == '__main__':
app = wx.PySimpleApp
frame = MyFrame()
frame.Show(True)
app.MainLoop
答案 0 :(得分:5)
你的缩进是完全奇怪的,这是我最好的猜测。我建议尝试从基础知识中学习更多Python。
#!/bin/env python
import wx
class MyFrame(wx.Frame):
def __init(self):
wx.Frame.__init__(self, None, -1,"My Frame", size=(300,300))
panel = wx.Panel(self, -1)
panel.Bind(wx.EVT_MOTION, self.OnMove)
wx.StaticText(panel,-1,"POS:",pos=(10, 12))
self.PosCtrl = wx.TextCtrl(panel, -1,"",pos=(40, 10))
def OnMove(self, event):
pos = event.GetPosition()
Self.PosCtrl.SetValue("%s, %s" % (pos.x,pos.y))
if __name__ == '__main__':
app = wx.PySimpleApp
frame = MyFrame()
frame.Show(True)
app.MainLoop
答案 1 :(得分:0)
您应该缩进if __name__ == '__main__':
下方的代码。
答案 2 :(得分:0)
从你粘贴的东西 您需要缩进OnMove并修复if 名称
答案 3 :(得分:0)
您的错误位于“if”块中:)
if __name__ == '__main__':
app = wx.PySimpleApp
frame = MyFrame()
frame.Show(True)
app.MainLoop
这是缩进错误:)
编辑:我发布了解决方案:)