Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 对象有参数,但表示它没有';T_Python_Python 3.x_Tkinter_Python 3.5 - Fatal编程技术网

Python 对象有参数,但表示它没有';T

Python 对象有参数,但表示它没有';T,python,python-3.x,tkinter,python-3.5,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:

当我运行代码时,它返回错误:

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')

即使对象的参数已定义。

正如其他人所指出的,您也需要在
\uuuu init\uuuu
中使用双下划线, 您错过了
create\u oval
call的参数:

TypeError: object() takes no parameters

def uuu init_uuu(self、canvas、color):#正如其他人所指出的,您需要在
中使用双下划线,
您错过了
create\u oval
call的参数:

TypeError: object() takes no parameters

def uuu init(self、canvas、color):#
_init
在python中没有什么特殊的含义。每侧需要两个下划线每侧需要两个下划线
\uuuuu init\uuuuuu
@cricket\u 007,只会显示更多错误通常会显示完整的错误消息(回溯)。哪一行有问题?好吧,这就解决了上面提到的错误,这是一个打字错误,因此这篇文章偏离了主题。尽管在python中,
\u init\u
没有什么特别的含义,但您仍然有时间。每侧需要两个下划线每侧需要两个下划线
\uuuuu init\uuuuuu
@cricket\u 007,只会显示更多错误通常会显示完整的错误消息(回溯)。哪一行有问题?好吧,这就解决了上面提到的错误,这是一个打字错误,因此这篇文章偏离了主题。不过,你还有时间