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.
Asked
Active
Viewed 2,837 times
2
matsjoyce
- 5,503
- 6
- 30
- 36
Sarvesh EB
- 81
- 1
- 9
-
@SarveshEB Which type of terminal are you using? – matsjoyce Mar 27 '15 at 17:23
-
@matsjoyce Just the default. This is how mine looks: [link](http://i.imgur.com/f50S3N7.png?1) – Sarvesh EB Mar 28 '15 at 01:29
1 Answers
4
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: