Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change cmd prompt size in Python

I am making a text-based CMD application in Python.

And I'd like it to resize the Command prompt to a more square, Text-based adventure-like, form.

So I found this:

os.system("mode con cols=93 lines=45")

However that's definitive and once set the user can no longer scroll on the CMD or resize the app.

So it makes it impossible for the user to read any bit of long text. Is there anyway to add an auto-scroll to the cmd or to resize the cmd without making it unusable?

like image 282
Tom Avatar asked Nov 24 '25 11:11

Tom


1 Answers

Using the win32 API, you can avoid losing the scroll:

from ctypes import windll, byref
from ctypes.wintypes import SMALL_RECT

STDOUT = -11

hdl = windll.kernel32.GetStdHandle(STDOUT)
rect = wintypes.SMALL_RECT(0, 50, 50, 80) # (left, top, right, bottom)
windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect))
like image 184
Keyan Kazemian Avatar answered Nov 27 '25 00:11

Keyan Kazemian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!