问题
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