对象有参数,但表示没有

时间:2016-11-12 04:58:05

标签: python python-3.x tkinter python-3.5

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

即使定义了对象的参数。

1 个答案:

答案 0 :(得分:3)

正如其他人指出的那样,你需要在pod 'SwiftyXMLParser', :git => 'https://github.com/yahoojapan/SwiftyXMLParser.git', :branch => "swift2.3" 中使用双下划线, 你错过了__init__电话的论据:

create_oval
相关问题