diff --git a/DemoPrograms/Demo_User_Settings_Remember_ComboBox.py b/DemoPrograms/Demo_User_Settings_Remember_ComboBox.py new file mode 100644 index 00000000..eaad3942 --- /dev/null +++ b/DemoPrograms/Demo_User_Settings_Remember_ComboBox.py @@ -0,0 +1,28 @@ +import PySimpleGUI as sg + +""" + Demo - Save previously entered strings as a Combobox entry 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 4 more lines of code to save the newly added + name into the saved list. + + Copyright 2020 PySimpleGUI.org +""" + + +def main(): + + layout = [[sg.T('This is your layout')], + [sg.T('Enter or choose name'), sg.Combo(sg.user_settings_get_entry('names', []), size=(20,1), k='-COMBO-')], + [sg.OK(), sg.Button('Exit')]] + + event, values = sg.Window('Pattern for theme saving', layout).read(close=True) + + if event == 'OK': + sg.user_settings_set_entry('names', list(set(sg.user_settings_get_entry('names', []) + [values['-COMBO-'],]))) + print(f"You chose {values['-COMBO-']}") + +if __name__ == '__main__': + main() +