Class Object Error with Tkinter Game From Python for Kids book http://python-for-kids.com -
i copying game book on learning python called python kids. website book python kids. code shown below.
from tkinter import * import random import time class ball: def _init_(self, canvas, color) self.canvas = canvas self.id = canvas.create_oval(10, 10, 25, 25, fill=color) self.canvas.move(self.id, 245, 100) def draw(self): pass tk = tk() tk.title('game') tk.resizable(0,0) tk.wm_attributes('-topmost, 1) canvas = canvas(tk, width=500, height=400, bd=0, highlightthickness=0) canvas.pack() tk.update() ball = ball(canvas, 'red') while 1: tk.update_idletasks() tk.update() time.sleep(0.01)
there additional spaces in program in order make easier understand, forgo these spaces in question. error shown below.
=============== restart: /users/gg-mac/documents/paddleball.py =============== traceback (most recent call last): file "/users/gg-mac/documents/paddleball.py", line 22, in <module> ball = ball(canvas, 'red') typeerror: object() takes no parameters >>>
i appreciate if help. if can, thank assistance.
looks class isn't defined correctly. no capital "c" in class , no parenthesis class itself... correct be:
class ball():
also, seems later call class canvas, don't seem have imports of tk or canvas here in snippet. in order use canvas must import somewhere. this:
from somewhere import canvas
Comments
Post a Comment