2020-10-16 18:06:34 +00:00
|
|
|
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.
|
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():
|
|
|
|
|
|
|
|
layout = [[sg.T('This is your layout')],
|
2020-10-16 18:28:31 +00:00
|
|
|
[sg.T('Enter or choose name'), sg.Combo(sorted(sg.user_settings_get_entry('names', [])), size=(20,1), k='-COMBO-')],
|
2020-10-20 13:34:42 +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':
|
|
|
|
sg.user_settings_set_entry('names', list(set(sg.user_settings_get_entry('names', []) + [values['-COMBO-'],])))
|
2020-10-20 13:34:42 +00:00
|
|
|
sg.user_settings_set_entry('input', values['-INPUT-'])
|
2020-10-16 18:06:34 +00:00
|
|
|
print(f"You chose {values['-COMBO-']}")
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-10-20 13:34:42 +00:00
|
|
|
sg.user_settings_filename(path='.')
|
2020-10-16 18:06:34 +00:00
|
|
|
main()
|
|
|
|
|