import PySimpleGUI as sg
def dialog():
layout = [[sg.Text("Value1:",size=(5,1)), sg.I(key="-VALUE1-",size=(10,1),focus=True)],
[sg.Text("Value2:", size=(5, 1)), sg.I(key="-VALUE2-", size=(10, 1),focus=True)],
[sg.Text("",size=(5,1)),sg.OK(key="-OK-"),sg.B("Show",key="-SHOW-"),sg.Cancel(key="-CANCEL-")]]
window = sg.Window("Inputdialog", layout,modal=True,finalize=True)
window.Element("-VALUE1-").SetFocus()
window["-VALUE1-"].bind('<FocusOut>', 'FOCUS OUT')
window["-VALUE2-"].bind('<FocusOut>', 'FOCUS OUT')
while True:
event, values = window.read()
print(event)
if event in (sg.WIN_CLOSED, "-CANCEL-"):
break
if event in ("-SHOW-"):
print(values)
if event in ("-OK-"):
return values
window.close()
result = dialog()
When i tab from one field to another, a Focusout is generated. But when i'm in an inputfield and push a button, the Focusout of that inputfield is not generated. How can the Focusout be forced anyway?
Default tk Button won't steal focus when clicked, but steal focus for ttk Button.