Change console font in Windows

后端 未结 7 1148
闹比i
闹比i 2020-11-30 12:04

Is there a way to change the console font in Windows in python 2.6?

I\'m on Windows 7.

ie:

import os
os.console.font = \'Lucida Console\'
         


        
7条回答
  •  执笔经年
    2020-11-30 12:30

    Well, I haven't dig deep enough to be able to choose font by name (and I doubt it is possible), but this code (provided that pywin32 is installed) seems to do something funny with it's console (must be cmd.exe, Console2 doesn't work, I don't know if it works with powershell):

    [C:Users/cji]|1> import win32console
    [C:Users/cji]|2> win32console.PyConsoleScreenBufferType( win32console.GetStdHandle( win32console.STD_OUTPUT_HANDLE )  )
             <2> 
    [C:Users/cji]|3> p = _
    [C:Users/cji]|6> p.SetConsoleFont( 1 )
    [C:Users/cji]|7> p.SetConsoleFont( 2 )
    # and so on, to:
    [C:Users/cji]|12> p.SetConsoleFont( 11 ) #this is Lucida Console, if I see correctly
    

    Documentation says, that SetConsoleFont "is not documented on MSDN"... But, it certainly does something with current console font, so I think you should search in this direction.

    Also, similar question: How can I change console font?

提交回复
热议问题