Search code examples
pythonconsoleheightwidthset

Set Console Width (Windows, Python)


I am working on a little text based console game using Python. Because I am using some ASCII art I have to ensure that the width of the console is the same for everyone after launch of my game. Can anyone tell me how to set the console width and height ? :)

Greetz

Flo


Solution

  • The easiest way is to execute the mode command.

    e.g. for a 80x25 window:

    C:\> mode con: cols=25 lines=80
    

    Or in Python:

    subprocess.Popen(["mode", "con:", "cols=25", "lines=80"])