I need to make sure user input entered in textbox with pysimplegui is integer or empty. For this I am following below method:
import PySimpleGUI as sg
sg.theme('SandyBeach')
layout = [
[sg.Text('Please enter your Phone')],
[sg.Text('Phone', size=(15, 1)), sg.InputText(key="lp1")],
[sg.Button("e"), sg.Quit()]
]
window = sg.Window('Simple data entry window', layout)
while True:
event, values = window.read()
if event == "e":
height = int(values['lp1'])
print(type(height))
if height == "" or type(height) == int:
print("s")
else:
print("n")
if event in [sg.WINDOW_CLOSED, "Quit"]:
break
window.close()
The issue here is if I make height = int(values['lp1']) & leave the input blank I get ValueError:
invalid literal for int() with base 10: '223d'
if I make height = height = values['lp1'] height type is str
also the expected output should be n when string is entered. Kindly suggest how to rectify it.