DeadBread76 / Raid-Toolbox

Raid ToolBox (RTB) is a big toolkit of Spamming/Raiding/Token management tools for discord.
GNU General Public License v2.0
438 stars 240 forks source link

Consider using the PySimpleGUI "User Settings" API to access your config.json file #139

Open PySimpleGUI opened 3 years ago

PySimpleGUI commented 3 years ago

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 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