From 645ab655a5c45aaf92f8639ca2faaa3d35e06137 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Tue, 20 Oct 2020 09:50:02 -0400 Subject: [PATCH] New user settings coding convention --- .../Demo_User_Settings_Remember_Input_and_Combo.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py b/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py index db9d9418..f17f2504 100644 --- a/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py +++ b/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py @@ -1,7 +1,7 @@ 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. 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(): 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('Remembers last value'), sg.In(sg.user_settings_get_entry('input', ''), k='-INPUT-')], + [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.OK(), sg.Button('Exit')]] event, values = sg.Window('Pattern for saving with Combobox', layout).read(close=True) if event == 'OK': - 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('-names-', list(set(sg.user_settings_get_entry('-names-', []) + [values['-COMBO-'],]))) + sg.user_settings_set_entry('-input-', values['-INPUT-']) print(f"You chose {values['-COMBO-']}") if __name__ == '__main__':