Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 689
Fourier Avatar asked Nov 01 '12 10:11

Fourier


1 Answers

a) To check the size of the Terminal Window

import os

x = os.get_terminal_size().lines
y = os.get_terminal_size().columns

print(x)
print(y)

b) To change the size of the Terminal Window

import os

cmd = 'mode 50,20'
os.system(cmd)

c) To change the color of the Terminal Window

import os

cmd = 'color 5E'     
os.system(cmd)
like image 65
Johan Conradie Avatar answered Sep 27 '22 02:09

Johan Conradie