Reputation: 103
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. I will be providing an in-program call to: sys.exit()
when required. I know there is a similar option available even for Java
GUI
programming.
Upvotes: 3
Views: 3987
Reputation: 5844
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. Note: I have not tested this, as I haven't got access to a Windows machine ATM.
References:
Upvotes: 6