Open cmd in full screen

Go To StackoverFlow.com

2

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.

2012-04-04 00:47
by user1311674
Have you tried just wrapping the text to, say, 80 columns - A B 2012-04-04 00:51
Thanks for the suggestion but after formatting all the paragraphs the text is still wrapped when the program is run in cmd from the exe - user1311674 2012-04-04 01:01
Do you know how many columns wide the cmd is - A B 2012-04-04 01:02
Well, when checking out the cmd layout properties, the width is set to 80. I figure that means 8 columns? IDLE is set to 80 as well so I figured I'd not have this problem - user1311674 2012-04-04 01:05
Can you post an example of what the broken formatting looks like and the source that printed it - A B 2012-04-04 01:07
Not sure how to add screen shots to show you what the cmd is doing, but I can re-create a sentence which has the formatting issues and then show you the source that produced that sentence... Give me a second.. - user1311674 2012-04-04 01:09
Hi,I changed the format paragraph width in Python to 70. This seemed to fix the formatting problem although not sure why as the cmd is the same size as Python. Anyway, what if another user is wanting to run the program and it starts off with terrible formatting. Is there no way to automatically open the game in full screen mode - user1311674 2012-04-04 01:17
Also, thank you for the formatting advice! Very new to cmd, python and cxfreeze. Seems I have much still to learn - user1311674 2012-04-04 01:18
There certainly could be, but I don't know how. (Thus why I'm commenting and not writing an actual answer. - A B 2012-04-04 01:18
I don't think there's any good way to control the size of the window that opens, because that's up to the operating system, although maybe there's something when you create the shortcut that can affect it. It might be possible to detect the terminal size and wrap your text accordingly using textwrap - Thomas K 2012-04-04 18:02
I will look into that, thanks. I was wondering about those older dos games I'd play where they'd open up in full screen. I figured there must be a way... oh well, I'll keep searching. Thanks again for the text wrap idea, though - user1311674 2012-04-05 15:07


3

If you are prepared to call some Windows API functions then you can make your console go full screen as follows:

  1. Call GetStdHandle passing STD_OUTPUT_HANDLE to get a handle the console handle.
  2. Call 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.

2012-04-05 15:27
by David Heffernan


1

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

2018-05-26 09:28
by Simon