Hello guys, I'm learning Python and there is a small problem in writing code for one game. I've created a Ball class with some attributes. And then, when I create a member of this class, I get a TypeError.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
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( 'Bounce!' ) tk.resizable( 0 , 0 ) tk.wm_attributes( '-topmost' , 1 ) canvas = Canvas(tk, width = 1800 , height = 1000 , bd = 1 , highlightthickness = 0 ) canvas.pack() tk.update() ball = Ball(canvas, 'red' ) while 1 : tk.update_idletasks() tk.update() time.sleep( 0.01 ) |
Error:Traceback (most recent call last):
File "D:/Games/скок!.py", line 20, in <module>
ball = Ball(canvas, 'red')
TypeError: Ball() takes no arguments
Please, help me!