I was wondering if it is possible to have a python exe made with cx_Freeze open in cmd full screen by default?
Thanks for any help.
If you are prepared to call some Windows API functions then you can make your console go full screen as follows:
GetStdHandle
passing STD_OUTPUT_HANDLE
to get a handle the console handle.SetConsoleDisplayMode
passing that console handle and CONSOLE_FULLSCREEN_MODE
.At this point your console window will be displaying full screen.
I don't know if those functions are readily available in one of the win32 Python modules but they are pretty trivial to invoke using ctypes.
There is no integrated cx_Freeze command to do this, however if you run on Windows, the Ctypes provides a way to do this using the WinAPI.
Example Code:
import ctypes
kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')
SW_MAXIMIZE = 3
hWnd = kernel32.GetConsoleWindow()
user32.ShowWindow(hWnd, SW_MAXIMIZE)
Explanation:
GetConsoleWindow()
:
See Documentation
Retrieves the window handle used by the console associated with the calling process.
Basically it gets the handle to the terminal so that ShowWindow()
knows what to modify.
ShowWindow(hWnd, SW_MAXIMIZE)
See Documentation
Sets the specified window's show state.
I.e. it tells the window what it should look like.
We pass our terminal handle (stored in hWnd
) to this function and call 3
to maximise.
See the nCmdShow
section for all options