I have simple GUI with two inputs and exit button. Inputs have default_value = 0.00. I want to validate user change in the way that input can be only float format,'.2f' and <= 5.0. Example from cookbook helps partially. When I use this code:
import PySimpleGUI as sg
layout = [[sg.Input(key='first_input', enable_events=True, default_text='0.00')],
[sg.Input(key='second_input', enable_events=True, default_text='0.00')],
[sg.Button('Exit')]]
window = sg.Window('Main', layout)
while True:
event, values = window.read()
if event in ['Exit', sg.WIN_CLOSED]:
break
if event == 'first_input' and values['first_input']:
try:
in_as_float = float(values['first_input'])
if float(values['first_input']) > 5:
window['first_input'].update('5')
except:
if len(values['first_input']) == 1 and values['first_input'][0] == '-':
continue
window['first_input'].update(values['first_input'][:-1])
window.close()
But when user delete content of "first_input" and decide to fill "second_input" the previous one remains empty. How to prevent it and for example back to default value when user left input empty.
I have tried to do someting like:
if values['first_input'] == '':
window['firs_input'].update['0.00']
but this do not work because it will not let to user delete content. For example when he want to change from 3 to 4. After he delete 3 0.00 apears immediately.