Class takes no arguments - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Class takes no arguments (/thread-27927.html) |
Class takes no arguments - Nazartfya - Jun-27-2020 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. 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) Please, help me!
RE: Class takes no arguments - Yoriz - Jun-27-2020 class Ball: def _init_(self, canvas, color):init should have double _ class Ball: def __init__(self, canvas, color): RE: Class takes no arguments - Nazartfya - Jun-27-2020 Thank you, Yoriz. |