Home > Software design >  How to share tkinter widget in a shelve store?
How to share tkinter widget in a shelve store?

Time:06-28

Is it possible to share a Tkinter widget using the shelve module?

For example:

from tkinter import *
import shelve

tk = Tk()
with shelve.open("store") as holder:
  holder["tk"] = tk

CodePudding user response:

I don't think it will work. From the shelve documentation:

A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle.

You can't store tkinter objects with pickle.

CodePudding user response:

Hi thanks to have ansow me. But I can do a stuff like that :

import shelve
class myClass:
    # do stuff

with shelve.open("store") as holder:
    holder["variable"] = myClass()

but I can't do that :

import shelve,tkinter
class myClass:
    def __init__(self):
        self.window= tk.Tk()

with shelve.open("store") as holder:
    holder["variable"] = myClass()

why ????

  • Related