Merge pull request #3514 from PySimpleGUI/Dev-latest

New user settings coding convention
This commit is contained in:
PySimpleGUI 2020-10-20 09:50:22 -04:00 committed by GitHub
commit 4b542e33d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -1,7 +1,7 @@
import PySimpleGUI as sg import PySimpleGUI as sg
""" """
Demo - Save previously entered strings as a Combobox entry by using user_settings calls Demo - Save previously entered strings for Input and Combo elements by using user_settings calls
It's literally 1 parameter in the layout to get the list of previously used entries shown. It's literally 1 parameter in the layout to get the list of previously used entries shown.
Then, when the OK button is clicked, it's one line of code to save the newly added Then, when the OK button is clicked, it's one line of code to save the newly added
@ -13,15 +13,15 @@ import PySimpleGUI as sg
def main(): def main():
layout = [[sg.T('This is your layout')], layout = [[sg.T('This is your layout')],
[sg.T('Enter or choose name'), sg.Combo(sorted(sg.user_settings_get_entry('names', [])), size=(20,1), k='-COMBO-')], [sg.T('Enter or choose name'), sg.Combo(sorted(sg.user_settings_get_entry('-names-', [])), size=(20,1), k='-COMBO-')],
[sg.T('Remembers last value'), sg.In(sg.user_settings_get_entry('input', ''), k='-INPUT-')], [sg.T('Remembers last value'), sg.In(sg.user_settings_get_entry('-input-', ''), k='-INPUT-')],
[sg.OK(), sg.Button('Exit')]] [sg.OK(), sg.Button('Exit')]]
event, values = sg.Window('Pattern for saving with Combobox', layout).read(close=True) event, values = sg.Window('Pattern for saving with Combobox', layout).read(close=True)
if event == 'OK': if event == 'OK':
sg.user_settings_set_entry('names', list(set(sg.user_settings_get_entry('names', []) + [values['-COMBO-'],]))) sg.user_settings_set_entry('-names-', list(set(sg.user_settings_get_entry('-names-', []) + [values['-COMBO-'],])))
sg.user_settings_set_entry('input', values['-INPUT-']) sg.user_settings_set_entry('-input-', values['-INPUT-'])
print(f"You chose {values['-COMBO-']}") print(f"You chose {values['-COMBO-']}")
if __name__ == '__main__': if __name__ == '__main__':