Python Forum
[Tkinter] Bounce Game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Bounce Game
#1
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)
 

	
Reply
#2
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)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020