Python Forum

Full Version: Bounce Game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was making this game from the Python book and I made it exactly as it had it in the book but when I asked python to check it before I ran it, it said,"inconsistent use of tabs and spaces in indentation" for line 7. Please tell me if you notice something wrong.
import time
import random
from tkinter import *

class Ball:
    def __init__(self, canvas, color):
	self.canvas = canvas
	self.id = cavas.create_oval(10, 10, 25, 25, fill=color)
	self.canvas.move(self.id, 245, 100)

		
    def draw(self):
        self.canvas.move(self.id, 0, -1)

tk = Tk()
canvas = Canvas(tk, width=400, height=400)
canvas.pack()
tk.title("Game")
tk.wm_attributes("-topmost", 1)
tk.title("Game")
canvas = Canvas(tk, width=400, height=400, bd=0, highlightthickness=0)
canvas.pack()
tk.update()

ball = Ball(canvas, 'red')

while 1:
        ball.draw()
	tk.update_idletasks()
	tk.update()
	time.sleep(0.01)
 

	
I believe the problem is with indentation here. Lines within the __init__ function should be indented:

def __init__(self, canvas, color):
    self.canvas = canvas
    self.id = cavas.create_oval(10, 10, 25, 25, fill=color)
    self.canvas.move(self.id, 245, 100)