class circle_color:
def __init__(self):
self.circle_red = canvas.create_oval(10, 160, 140, 290, fill="red")
self.circle_blue = canvas.create_oval(10, 10, 140, 140, fill="blue")
def circle_blue_add(self):
return self.circle_blue
def circle_red_add(self):
return self.circle_red
but_circle_blue_add = Button(panel_with_button, text="Add Blue Circle", width=20, command=circle_color.circle_blue_add)
but_circle_blue_add.place(x=10, y=10)
but_circle_blue_del = Button(panel_with_button, text="Add Red Circle", width=20, command=circle_color.circle_blue_add)
but_circle_blue_del.place(x=10, y=50)'
此错误
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Fleshka\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1549, in __call__
return self.func(*args)
TypeError: circle_blue_add() missing 1 required positional argument: 'self'
我需要用oop编程绘制两个图一蓝色和红色。但我不明白为什么它不起作用
答案 0 :(得分:1)
您尝试调用类方法(我猜测的不是您实际想做的事情)。您需要创建类的实例,并调用实例的方法。
{{1}}