In-game save feature (in tkinter game)
<p>I'm working on a text-based game in Python using Tkinter. All the time the window contains a Label and a few Buttons (mostly 3). If it didn't have GUI, I could just use Pickle or even Python i/o (.txt file) to save data and later retrieve it.  But what is the best way to tell the program to load the exact widgets without losing bindings, buttons' commands, classes etc.?  P.S.: Buttons lead to cleaning the frame of widgets and summoning new widgets. I'm thinking of assigning a lambda (button's command) to a variable and then saving it (Pickle?) to be able to load it in the future and get the right point in the plot. Should I go for it or is there a better, alternative way to accomplish the thing? (If using lambda may work, I'd still be grateful to see your way of doing that.)</p>

<p>My understanding was that you need a widget manager, to put them where you want and it is easy to pick up values.</p>

<p>Create a new class called Manager, make two functions, _setNewWidget, _deleteWidget, like this:</p>

<pre><code>class Manager():
    def __init__(self, *args, **kwargs):
        objects = {}

    def _createButton(self, frame, id, function, etc):
        # object[id] = frame.Button(function, etc, ...) i dnt' know sintaxes, but this is the way

    def _deleteWidget(self, id):
        # object[id] = None or del(object[id]) same here
</code></pre>

<p>To get, just:</p>

<pre><code>manager = Manager()
manager._createWidget("button_fase_one", frameTk, etc, etc)
manager.objects["button_fase_one"].changeFrame() # example
print(manager.objects["button_fase_one"].text)
</code></pre>

<p>In this way u can create objects and blit where u want.</p>

<p>To save data just make another function and save as json.</p>

python tkinter