0

I m getting "expected indented block" error in below code : i am new to python please help

#!/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
orlp
  • 112,504
  • 36
  • 218
  • 315
kamlesh
  • 1
  • 1
  • Tangentially, the code you put inside `if _ name__ == ’__main__’:` should be absolutely trivial. The condition is only useful when you `import` this code; if all the useful functionality is excluded when you `import`, you will never want to do that anyway. See also https://stackoverflow.com/a/69778466/874188 – tripleee Jan 16 '22 at 12:24

4 Answers4

5

Your indenting is completely strange, this is my best guess. I would suggest to try and learn Python more from the basics up.

#!/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
orlp
  • 112,504
  • 36
  • 218
  • 315
  • The stuff under `if __name__ == '__main__':` is double indented, so I'd move them back one level and it'll be golden methinks. – TyrantWave Jun 29 '11 at 10:14
  • Ahh, you posted the comment while I still was editing, thought you were talking about the OP. – orlp Jun 29 '11 at 10:31
0

You should probably indent the code below if __name__ == '__main__':.

onemasse
  • 6,514
  • 8
  • 32
  • 37
0

From what you pasted you need to de indent the OnMove and fix the if name

Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91
0

Your error is in the "if" block :)

if __name__ == '__main__':
        app = wx.PySimpleApp
        frame = MyFrame()
        frame.Show(True)
        app.MainLoop

This is the indentation error :)

Edit: i posted you the solution :)

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • 1
    Three smileys in one answer? Seriously? Perhaps you should start ending sentences with a dot instead of a smiley. – orlp Jun 29 '11 at 10:31
  • I was trying to be educate with user... It's seem to be that you don't know what "education" is... – DonCallisto Jun 29 '11 at 10:34
  • 1
    I very well know what education is, and you should back off a bit. I simply gave you a tip that will give people a better impression of you on the internet and you instantly attack me on something completely unrelated. – orlp Jun 29 '11 at 10:39