Windows命令提示符设置字符大小

时间:2015-06-21 22:01:15

标签: python windows python-2.7 command-line command-prompt

有一个命令将命令提示符字符大小设置为10x18?并且..我可以使用os.system()函数在python脚本中执行此操作吗?

Screenshot of the gui settings
谢谢

1 个答案:

答案 0 :(得分:0)

要更改命令提示符的大小:

import os
os.system("mode con cols=18 lines=10") # cols for the width and lines for the length

要更改命令提示符的字符大小:

import ctypes

STD_OUTPUT_HANDLE = -11

class COORD(ctypes.Structure):
    _fields_ = [("X", ctypes.c_short), ("Y", ctypes.c_short)]

class CONSOLE_FONT_INFOEX(ctypes.Structure):
    _fields_ = [("cbSize", ctypes.c_ulong),
                ("nFont", ctypes.c_ulong),
                ("dwFontSize", COORD)]

font = CONSOLE_FONT_INFOEX()
font.cbSize = ctypes.sizeof(CONSOLE_FONT_INFOEX)
font.nFont = 12
font.dwFontSize.X = 10  # in your case X=10
font.dwFontSize.Y = 18  # and Y=18



handle = ctypes.windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
ctypes.windll.kernel32.SetCurrentConsoleFontEx(
        handle,False, ctypes.byref(font))