[Tutor] Change Font Size when print to screen

Tim Golden mail at timgolden.me.uk
Tue Jan 11 10:21:26 CET 2011


On 11/01/2011 09:03, tee chwee liong wrote:
> When I do print "Hello World", it will print to the cmd window with
> the standard font size. Is there a way we can increase the font size
> to larger when print out to the cmd window?

I'm going to assume that you're using Windows, since you
refer to the "cmd window". If you're on Linux or OS X the
answer will be different.

In short, this isn't straightforward. The Python interpreter
simply sends text to the console and the console renders it
using whatever font and size have been selected by the user.

You can set the font & size of any console window (and save
it as the default) by using the System Menu -- left-click at
the top-left of the Window.

But if you want a particular Python script to have the power
to write smaller or larger text on demand, you're going to
need to control the console functions directly. You can do
this via the win32console module of the pywin32 modules:

   http://sourceforge.net/projects/pywin32/

or by rolling the same thing yourself from within Python via ctypes:

   http://docs.python.org/library/ctypes.html

I'm not aware that you can have a mixture of smaller and larger
(or different) fonts on one console window. AFAICT you can set
the font/size for the whole console but nothing else. If you need
more control, you're going to have to move to some kind of
GUI solution.

TJG


More information about the Tutor mailing list