Python今天不喜欢我。它正在翻译语法错误预期在第三个def处的缩进块。我已删除所有标签并放入空格(每个标签4个),但仍然没有变化。
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()
答案 0 :(得分:3)
如果这就是您的代码实际上看起来的样子,那么只需更换“#do something'通过'传递'
如果你在那里有一些实际的代码,那就是' #do something'只是告诉SO用户你在那里做某事的方式请告诉我们你在那里做什么,发布完整的代码。