简体   繁体   English

在 Python 中更改 cmd 提示大小

[英]Change cmd prompt size in Python

I am making a text-based CMD application in Python.我正在用 Python 制作一个基于文本的 CMD 应用程序。

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.然而,这是确定的,一旦设置,用户就不能再在 CMD 上滚动或调整应用程序的大小。

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?无论如何要向 cmd 添加自动滚动或调整 cmd 的大小而不使其无法使用?

Using the win32 API, you can avoid losing the scroll:使用 win32 API,您可以避免丢失滚动:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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