[英]Disable close button of console window
I want to control usage of the [X]
button (the exit window button), which is generally present in the top-right corner when running a console-based Python
application. 我想控制
[X]
按钮(退出窗口按钮)的用法,当运行基于控制台的Python
应用程序时,该按钮通常位于右上角。 I will be providing an in-program call to: sys.exit()
when required. 需要时,我将提供程序内调用:
sys.exit()
。 I know there is a similar option available even for Java
GUI
programming. 我知道即使
Java
GUI
编程也有类似的选项。
Try: 尝试:
import win32console, win32gui, win32con
hwnd = win32console.GetConsoleWindow()
if hwnd:
hMenu = win32gui.GetSystemMenu(hwnd, 0)
if hMenu:
win32gui.DeleteMenu(hMenu, win32con.SC_CLOSE, win32con.MF_BYCOMMAND)
It requires the pywin32 modules to be installed. 它需要安装pywin32模块。 Note: I have not tested this, as I haven't got access to a Windows machine ATM.
注意:由于没有访问Windows计算机ATM的权限,因此我尚未对此进行测试。
References: 参考文献:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.