简体   繁体   中英

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?

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM