More "Demo Program Catchup" updates. Working through them bit by bit.....

This commit is contained in:
PySimpleGUI 2022-02-22 05:20:03 -05:00
parent 1eb653d910
commit f1e0c7d03f
9 changed files with 87 additions and 57 deletions

View file

@ -2,8 +2,10 @@ import PySimpleGUI as sg
"""
Simple field validation
Input field should only accept digits.
Input field should only accept digits 0-9.
If non-digit entered, it is deleted from the field
Copyright 2022 PySimpleGUI
"""
layout = [[sg.Text('Enter digits:')],
@ -14,11 +16,12 @@ window = sg.Window('Window Title', layout)
while True: # Event Loop
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
break
# if last char entered not a digit
if len(values['-INPUT-']) and values['-INPUT-'][-1] not in ('0123456789'):
if event == '-INPUT-' and len(values['-INPUT-']) and values['-INPUT-'][-1] not in ('0123456789'):
# delete last char from input
window['-INPUT-'].update(values['-INPUT-'][:-1])
window.close()
window.close()