Reputation: 320
My question is clear. How can I set background color of console with python ? I know that we can set background color of console in C#. So I thought that python can do it, too. But how ? I'm on Windows and I use python 2.7.3. Thanks...
Upvotes: 5
Views: 17754
Reputation: 4278
Depends on the shell and terminal emulator you are working running on. For bash
this should work on ubuntu's terminal.
import os
color = 'blue'
os.system('setterm -term linux -back $'+color+' -fore white -clear')
Upvotes: 0
Reputation: 49318
You can set the Windows cmd console color with the color
command, passing it from Python via os.system
:
>>> import os
>>> os.system('color 1f') # sets the background to blue
For Linux terminals, use the setterm
command:
>>> import os
>>> os.system('setterm -background white -foreground white -store')
Upvotes: 8