0

Python does not like me today. It's trowing the syntax error Expected an indented block at third def. I've removed all tabs and put in spaces (4 at each) but still no change.

class CanvasClass:
    def __init__(self):
        window = Tk()
        window.title("Ball Move")

        self.canvas = Canvas(window, width=300, height=300, bg="white")
        self.canvas.pack()

        frame = Frame(window)
        frame.pack()
        btLeft = Button(frame, text="Left", command=self.moveLeft)
        btRight = Button(frame, text="Right", command=self.moveRight)
        btUp = Button(frame, text="Up", command=self.moveUp)
        btDown = Button(frame, text="Down", command=self.moveDown)

        btLeft.grid(row=1, column=1)
        btRight.grid(row=1, column=2)
        btUp.grid(row=1, column=3)
        btDown.grid(row=1, column=4)

        self.canvas.create_oval(10, 10, 50, 50, fill="red", tags="oval")

        window.mainloop()


    def moveRight(self):
        #do something

    def moveLeft(self):
        #do something

    def moveUp(self):
        #do something

    def moveDown(self):
        #do something

CanvasClass()

CodeMonkey
  • 1,136
  • 16
  • 31
  • Always put something in your functions. Like just a 0, otherwise python won't be able to parse your code. – kyflare Oct 26 '14 at 21:37
  • 1
    `pass` is commonly used for mocking empty functions or even better `raise NotImplementedError` – aseeon Oct 26 '14 at 21:39
  • at the third def but not at the second? Strange – Tim Oct 26 '14 at 21:41
  • @TimCastelijns not at all, second def is alright, python is just waiting for some proper line beneth it, and at the third def line it is sure it found an error and raises the exception. – aseeon Oct 26 '14 at 21:43
  • Wholly crap, i'm an idiot. The pass for the empty function did the trick.. Wow, i'm just failing hard today. Thanks! – CodeMonkey Oct 26 '14 at 21:46

1 Answers1

3

If this is how your code actually looks like just replace '#do something' with 'pass'.

If you have some actual code there and '#do something' is just your way of telling SO users that you are doing something there please tell us what are you doing there, post full code.

Pawel Miech
  • 7,742
  • 4
  • 36
  • 57