0
from tkinter import *
import random
import time
tk = Tk()
tk.title("Pong")
tk.resizable(0,0)
tk.wm_attributes("-topmost", 1)
canvas = Canvas(tk, width=500, height=400, bd=0, highlightthickness=0)
canvas.pack()
tk.update()
class Ball:
def _init_(self, canvas, color):
self.canvas = canvas
self.id = canvas.create_oval()
self.canvas.move(self.id, 245, 100)
def draw(self):
pass
ball = Ball(canvas, 'red')
當我運行的代碼,它會返回錯誤:對象有參數,但表示不
TypeError: object() takes no parameters
即使對象的參數定義。
'_init_'意味着什麼在Python特殊。每邊需要兩個下劃線 –
你需要在每一邊有兩個下劃線'__init__' –
@ cricket_007,這隻會帶來更多的錯誤 – user7148779