1

so I'm trying to resize the console window to the maximum size on startup.

I tried using the win32api as follows:

import win32api

console_handle = win32api.GetStdHandle(win32api.STD_OUTPUT_HANDLE)
win32api.SetConsoleDisplayMode(console_handle, CONSOLE_FULLSCREEN_MODE)

But it says that win32api doesn't have a SetConsoleDisplayMode function.

3 Answers3

2

I modified the code from this link to achieve it: How do I get monitor resolution in Python?

This is my code below which looks at the maximum size of the screen and fills the screen if its bigger than a predetermine size (1366 x 768). The screen resolution size 1366 x 768 is the smallest I can display my program.

from win32api import GetSystemMetrics

print("Width =", GetSystemMetrics(0))
print("Height =", GetSystemMetrics(1))

if GetSystemMetrics(0) >= 1366 and GetSystemMetrics(1) >= 768:
    Window.size = (GetSystemMetrics(0), GetSystemMetrics(1))
    Window.fullscreen = True
else: 
    Window.size = (1366, 768)

This worked on a 'windows' system for me. You'll have to test for other systems.

0

There's a windows command to change the size of the console:

import os
os.system("mode con cols=50 lines=20")

cols is the width, lines is the height

Ethan Brews
  • 131
  • 1
  • 5
  • thank you! Helped a lot. But another thing is how can I position the console so it doesn't stick out, because this way the console is as large as I need but right and bottom sides are sticking out of the screen, any idea how to fix it? – Jakub Fertáľ Jul 12 '17 at 15:13
0

Use win32console instead of win32api:

import win32console
h = win32console.GetStdHandle(win32console.STD_OUTPUT_HANDLE)
h.SetConsoleDisplayMode(win32console.CONSOLE_FULLSCREEN_MODE, win32console.PyCOORDType(0,0))
Maurice Meyer
  • 17,279
  • 4
  • 30
  • 47