【发布时间】:2015-09-07 07:15:28
【问题描述】:
有设置命令提示符字符大小为 10x18 的命令吗?而且.. 我可以在 python 脚本中使用os.system() 函数来执行此操作吗?
谢谢
【问题讨论】:
标签: python windows python-2.7 command-line command-prompt
有设置命令提示符字符大小为 10x18 的命令吗?而且.. 我可以在 python 脚本中使用os.system() 函数来执行此操作吗?
谢谢
【问题讨论】:
标签: python windows python-2.7 command-line command-prompt
更改命令提示符的大小:
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))
【讨论】:
FontFamily 和 FontWeight?例如,FontFamily (54 & 0xf == 6) 的低 4 位表示 TrueType、固定间距字体。高 4 位 (48) 表示“现代”字体系列。出于某种奇怪的原因,您似乎坚定地避免致电GetCurrentConsoleFontEx。
nFont 索引处的记录,又将其设置为当前字体。 OP只需要修改当前字体记录的dwFontSize即可,调用ctypes.windll.kernel32.GetCurrentConsoleFontEx(handle, False, ctypes.byref(font))即可。