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

This Error

 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'

I need to draw two figure one blue and red with oop programming. But I do not understand why it doesn't work

2
  • It's object-oriented, and you don't have an object there. Commented Dec 10, 2015 at 23:08
  • To clarify, the circle_blue_add method is expecting that you pass it self (an instance of the class), and you didn't. Please expand your code sample into an MCVE so we can determine the changes that would be most appropriate for your program. Commented Dec 10, 2015 at 23:10

1 Answer 1

1

You're attempting to call a class method (which I'm guessing is not what you actually want to do). You need to make an instance of the class, and call the instance's methods.

cc = circle_color()
but_circle_blue_add = Button(panel_with_button, text="Add Blue Circle", width=20, command=cc.circle_blue_add)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you it work ,but when I was running my program already figure on the screen instead of pressing the button
Yes, __init__ is a "magic" method that gets called when you instantiate a class, i.e. upon circle_color().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.