From ece20996a369e041e881c1faf490d2569de73e34 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Tue, 19 Jul 2022 08:46:01 -0400 Subject: [PATCH] Very Short Demo Program that saves the last value entered into Input element that is then used as the default in the future. --- ...t_Save_Last_Used_Entry_In_User_Settings.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 DemoPrograms/Demo_Input_Save_Last_Used_Entry_In_User_Settings.py diff --git a/DemoPrograms/Demo_Input_Save_Last_Used_Entry_In_User_Settings.py b/DemoPrograms/Demo_Input_Save_Last_Used_Entry_In_User_Settings.py new file mode 100644 index 00000000..6e5684cd --- /dev/null +++ b/DemoPrograms/Demo_Input_Save_Last_Used_Entry_In_User_Settings.py @@ -0,0 +1,31 @@ +import PySimpleGUI as sg + +""" + Demo - Save previously entered value in Input element by using user_settings calls + + Tired of typing in the same value or entering the same filename into an Input element? + If so, this may be exactly what you need. + + It simply saves the last value you entered so that the next time you start your program, that will be the default + + Copyright 2022 PySimpleGUI.org +""" + + +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('Remembers last value for this:'), sg.In(sg.user_settings_get_entry('-input-', ''), k='-INPUT-')], + [sg.OK(), sg.Button('Exit')]] + + # make a window, read it, and automatically close after 1 event happens (button or X to close window) + event, values = sg.Window('Save Input Element Last Value', layout).read(close=True) + + # only save the value if OK was clicked + if event == 'OK': + sg.user_settings_set_entry('-input-', values['-INPUT-']) + +if __name__ == '__main__': + main() +