M
M
mrdrkot2022-02-08 23:51:42
Python
mrdrkot, 2022-02-08 23:51:42

Python 3 kivy. How to save the state of the program?

I wrote an application where the states of widgets are described by a sufficiently large number of parameters. Now we need to somehow save these states to a file, and then load them again. I understand that you can write a save system where the function carefully takes the parameters of each widget and writes it to a dictionary. But it's a long time to write, there are a lot of parameters, widgets are different. In addition, when loading, you need to prescribe the creation of widgets according to these parameters.

Tried pickle, including with highProtocol , writes no default __reduce__ due to non-trivial __cinit__

Is there a way to quickly write the state of the root widget and all its children to a file, and then also easily create a root widget from this file in the saved state?

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-02-09
@mrdrkot

Look at the question from the other side.
The state of the widgets is probably determined by something else - the state of the application, which is described in terms of the subject area with which you are dealing.
Describe the state of the application as a class, learn how to save / load it without being tied to the GUI.
Then learn how to create a GUI based on an instance of this class.
And then change the instance of this class during GUI operations.
Read about the Model-View-Intent pattern, it is about this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question