简体   繁体   English

强制覆盖 PySimpleGUI window

[英]Force overlay a PySimpleGUI window

I just want that if someone tries to close the GUI window using close button instead of clicking "OK", the window reappears... In simple words, they cannot close this one or access any other window without clicking "OK".我只是希望,如果有人尝试使用关闭按钮而不是单击“确定”来关闭 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()

It is defined in source code of PySimpleGUI.它在 PySimpleGUI 的源代码中定义。 You can change it to generate an event "WIN_CLOSE", like this您可以更改它以生成事件“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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM