From 9e4bf95b33fca9ebbccf79e64db1c881c6c2125e Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Fri, 13 Nov 2020 11:54:39 -0500 Subject: [PATCH] Added last value chosen for combo, popup with dictionary info. --- .../Demo_User_Settings_Remember_Input_and_Combo.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py b/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py index f17f2504..48c8d828 100644 --- a/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py +++ b/DemoPrograms/Demo_User_Settings_Remember_Input_and_Combo.py @@ -11,9 +11,13 @@ import PySimpleGUI as sg """ def main(): + sg.user_settings_filename(path='.') # The settings file will be in the same folder as this program 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(values=sorted(sg.user_settings_get_entry('-names-', [])), + default_value=sg.user_settings_get_entry('-last name chosen-', None), + 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')]] @@ -21,10 +25,12 @@ def main(): if event == 'OK': sg.user_settings_set_entry('-names-', list(set(sg.user_settings_get_entry('-names-', []) + [values['-COMBO-'],]))) + sg.user_settings_set_entry('-last name chosen-', values['-COMBO-']) sg.user_settings_set_entry('-input-', values['-INPUT-']) - print(f"You chose {values['-COMBO-']}") + sg.popup(f"You chose {values['-COMBO-']} and input {values['-INPUT-']}", + 'The settions dictionary:', sg.user_settings()) + if __name__ == '__main__': - sg.user_settings_filename(path='.') main()