强制覆盖 PySimpleGUI window

Force overlay a PySimpleGUI window

我只希望如果有人尝试使用关闭按钮而不是单击“确定”来关闭 GUI window,window 会重新出现...简单来说,他们无法关闭这个或在不单击“确定”的情况下访问任何其他 window。

import PySimpleGUI as sg

layout = [[sg.Text("Click OK to start the unlock process using Face Verification")], 
          [sg.Button("OK")]]

# Create the window
window = sg.Window("Demo", layout)

# Create an event loop
while True:
    event, values = window.read()
    # End program if user closes window or
    # presses the OK button
    if event == "OK" or event == sg.WIN_CLOSED:
        break

window.close()

它在PySimpleGUI 的源代码中定义。 您可以更改它以生成一个事件“WIN_CLOSE”,就像这样

import PySimpleGUI as sg

layout = [[sg.Text("Click OK to start the unlock process using Face Verification")], [sg.Button("OK")]]
window = sg.Window("Title", layout, finalize=True)

window.TKroot.protocol("WM_DESTROY_WINDOW", lambda:window.write_event_value("WIN_CLOSE", ()))
window.TKroot.protocol("WM_DELETE_WINDOW",  lambda:window.write_event_value("WIN_CLOSE", ()))

while True:
    event, values = window.read()
    print(event)
    if event in ("OK", sg.WIN_CLOSED):
        break
    elif event == "WIN_CLOSE":
        print("Close Button 'X' clicked !")

window.close()
WIN_CLOSE
Close Button 'X' clicked !
WIN_CLOSE
Close Button 'X' clicked !
WIN_CLOSE
Close Button 'X' clicked !
OK