2020-10-16 18:06:34 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
|
|
|
"""
|
2020-10-20 13:50:02 +00:00
|
|
|
Demo - Save previously entered strings for Input and Combo elements by using user_settings calls
|
2020-10-16 18:06:34 +00:00
|
|
|
|
|
|
|
It's literally 1 parameter in the layout to get the list of previously used entries shown.
|
2020-10-20 13:34:42 +00:00
|
|
|
Then, when the OK button is clicked, it's one line of code to save the newly added
|
2020-10-16 18:06:34 +00:00
|
|
|
name into the saved list.
|
|
|
|
|
|
|
|
Copyright 2020 PySimpleGUI.org
|
|
|
|
"""
|
|
|
|
|
|
|
|
def main():
|
2020-11-13 16:54:39 +00:00
|
|
|
sg.user_settings_filename(path='.') # The settings file will be in the same folder as this program
|
2020-10-16 18:06:34 +00:00
|
|
|
|
|
|
|
layout = [[sg.T('This is your layout')],
|
2020-11-13 16:54:39 +00:00
|
|
|
[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-')],
|
2020-10-20 13:50:02 +00:00
|
|
|
[sg.T('Remembers last value'), sg.In(sg.user_settings_get_entry('-input-', ''), k='-INPUT-')],
|
2020-10-16 18:06:34 +00:00
|
|
|
[sg.OK(), sg.Button('Exit')]]
|
|
|
|
|
2020-10-16 18:28:31 +00:00
|
|
|
event, values = sg.Window('Pattern for saving with Combobox', layout).read(close=True)
|
2020-10-16 18:06:34 +00:00
|
|
|
|
|
|
|
if event == 'OK':
|
2020-10-20 13:50:02 +00:00
|
|
|
sg.user_settings_set_entry('-names-', list(set(sg.user_settings_get_entry('-names-', []) + [values['-COMBO-'],])))
|
2020-11-13 16:54:39 +00:00
|
|
|
sg.user_settings_set_entry('-last name chosen-', values['-COMBO-'])
|
2020-10-20 13:50:02 +00:00
|
|
|
sg.user_settings_set_entry('-input-', values['-INPUT-'])
|
2020-11-13 16:54:39 +00:00
|
|
|
sg.popup(f"You chose {values['-COMBO-']} and input {values['-INPUT-']}",
|
|
|
|
'The settions dictionary:', sg.user_settings())
|
|
|
|
|
2020-10-16 18:06:34 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|