can't pickle _tkinter.tkapp objects error when trying to create multiple instances of the same class

无人久伴 提交于 2021-02-10 15:15:29

问题


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

回答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.



来源:https://stackoverflow.com/questions/50568880/cant-pickle-tkinter-tkapp-objects-error-when-trying-to-create-multiple-instanc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!