尝试创建同一类的多个实例时,无法腌制 _tkinter.tkapp 对象错误 [英] can't pickle _tkinter.tkapp objects error when trying to create multiple instances of the same class

查看:121
本文介绍了尝试创建同一类的多个实例时,无法腌制 _tkinter.tkapp 对象错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为这个问题,我变得非常沮丧.我以前有过它,我修复了它,但是当我更改代码中的某些内容时它又回来了.准确地说,当我按下一个按钮时,我试图创建一个类的多个实例.我在 tkinter 中使用 python 3.6.当我第一次编写我的课程时,我使用了一个矩形(通过使用 create_rectangle 方法创建)进行可视化表示.在我的班级按照我想要的方式行事后,我想用一张照片而不是矩形出现在我的画布上.正如标题所暗示的那样,我的主要错误是不能腌制 _tkinter.tkapp 对象",在此之前有很多关于 deepcopy 的错误.这是完整的错误 https://pastebin.com/nAQifmnA

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

在使用图像之前,此修复有效无法腌制 _tkinter.tkapp 对象

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

我忘了提及,对于图像,我使用的是 PhotoImage 类.

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

推荐答案

Tkinter 小部件和画布项只是嵌入 tcl 解释器中存在的对象的薄包装.您不能使用 deepcopypickle 来创建多个实例,因为这些命令对嵌入式 tcl 解释器一无所知.如果需要多个实例,则必须调用适当的 tkinter 函数.

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.

这篇关于尝试创建同一类的多个实例时,无法腌制 _tkinter.tkapp 对象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆