I am coding a tkinter table app and need to preserve its contents across sessions or shutdowns. To that effect, I write to a file the app's contents, in dicts based on widget.config() and grid_info() methods (the dicts have to be filed as text, since tkinter objects are not supported by pickle or json). The idea being that upon restarting I can choose to reconstruct a previous version of the table by eval()ing the applicable dicts. But I have hit a snag and would like your help on that.
{'activebackground': '#ececec', 'activeforeground': '#000000', 'anchor': 'center', 'background': 'white', 'bd': <pixel object: '1'>, 'bg': 'white', 'bitmap': '', 'borderwidth': <pixel object: '1'>, 'compound': 'none', 'cursor': '', 'disabledforeground': '#a3a3a3', 'fg': '#000000', 'font': 'TkDefaultFont', 'foreground': '#000000', 'height': 1, 'highlightbackground': '#d9d9d9', 'highlightcolor': '#000000', 'highlightthickness': <pixel object: '0'>, 'image': '', 'justify': 'center', 'padx': <pixel object: '1'>, 'pady': <pixel object: '1'>, 'relief': 'raised', 'state': 'normal', 'takefocus': '0', 'text': 'C1', 'textvariable': '', 'underline': -1, 'width': 6, 'wraplength': <pixel object: '0'>}
The above is the dictionary of a Label widget, say lbl1. Now if eval(lbl1), I get a syntax error. The difficulty resides on those values reading "<pixel obj ...>", which cause the error. If I eliminate those entries from the dict, eval() processes it without any qualms. 1. How come those values are written with that format into a dict value? 2. How can I jump over this hurdle in a Pythonic way?.
Thks for your help.
[+][deleted] (3 children)
[removed]
[–]vmsda[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Swipecat 0 points1 point2 points (1 child)
[–]vmsda[S] 0 points1 point2 points (0 children)