1

I'm becoming really frustrated because of this problem. I had it before and i fixed it, but it came back again when i changed something in my code. To be precise i'm trying to create multiple instances of a class when i'm pressing a button. I am using python 3.6 with tkinter. When i was first writing my class i was using a rectangle (created by using create_rectangle method) for visual representation. After my class was behaving the way i wanted it to i wanted to use a photo to apear on my canvas instead of the rectangle. As the title sugested my main error is "can't pickle _tkinter.tkapp objects" and before that there are a lot of errors about deepcopy. This is the full error https://pastebin.com/nAQifmnA

Before using an image this fix worked Can't pickle _tkinter.tkapp objects

I forgot to mention, for the image i am using PhotoImage class.

This is where i try to create more instances of the class. This method is inside the actual class, maybe that's the problem? I tried different things but they are not working.

def newAdd():
      global And_list
      test=AND(10,10)
      And_list.append(deepcopy(test))
      And_list =listRecord()
4
  • You can't create multiple of the same tkinter object, you have to create them again. Commented May 28, 2018 at 16:19
  • Ok, can you give me an example of how to create more objects of the same kind? i don't want it to be something like instance1= myClass, instance2= myClass, instead i want to use a function to create more objects when called Commented May 28, 2018 at 17:17
  • def new(): inst=Myclass() return inst. Then to create a new one: inst1=new(). (Though I don't see what difference it make with your example.... Commented May 28, 2018 at 20:53
  • it's ok, i fixed it, the only thing i really needed was " test=AND(10,10)", the other parts were useless and causing errors giving no actual benefits to my code, ty a lot for the help Commented May 29, 2018 at 9:38

1 Answer 1

1

Tkinter widgets and canvas items are just thin wrappers around objects that exist in an embedded tcl interpreter. You can't use deepcopy or pickle to create multiple instances because those commands know nothing about the embedded tcl interpreter. If you need multiple instances, you must call the appropriate tkinter functions.

Sign up to request clarification or add additional context in comments.

Comments

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.