Using the PySimpleGUI User Settings APIs means you don't need to bother with loading and saving the file. PySimpleGUI takes care of the loads and saves for you. It acts like a "persistent dictionary" that simply exists globally that you never have to explicitly save. Changing a value is all that it takes to save the dictionary.
Here's an example that prints out one of the settings and modifies another. When creating the UserSettings object, I assumed that the file config.json is in the same folder as the application.
import PySimpleGUI as sg
settings = sg.UserSettings(r'.\config.json')
print(settings['skin'])
settings['use_proxies'] = 1
print(settings) # prints the entire dictionary
Release 4.31.0 of PySimpleGUI posted today and it has an easy way for you to work with your config.json file.
You'll find this part of the PySimpleGUI SDK documented here: https://pysimplegui.readthedocs.io/en/latest/#user-settings-api
Using the PySimpleGUI User Settings APIs means you don't need to bother with loading and saving the file. PySimpleGUI takes care of the loads and saves for you. It acts like a "persistent dictionary" that simply exists globally that you never have to explicitly save. Changing a value is all that it takes to save the dictionary.
Here's an example that prints out one of the settings and modifies another. When creating the
UserSettings
object, I assumed that the fileconfig.json
is in the same folder as the application.