如何在python中获取Windows控制台的大小

时间:2012-05-09 17:29:16

标签: python windows winapi console

我需要一些程序来获取控制台的当前窗口大小

我试过以下程序

def get_windows_term_width():
    from ctypes import windll, create_string_buffer
    h = windll.kernel32.GetStdHandle(-12)
    csbi = create_string_buffer(22)
    res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
    if res:
       import struct
       (bufx, bufy, curx, cury, wattr,
       left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
       sizex = right - left + 1
    else:
       sizex = 90
    return sizex

但即使我更改cmd.exe中的设置

,我的默认设置为sizex = 90

0 个答案:

没有答案