1

I am new to Python and recently I've made a Mastermind game, and right now I use X and O for checking if you guessed right, but if it possible that I for example use colors for this? I can't find an answer online, I've only found something like

x = Color('#FF0000')

but that doesn't work, it gives me a syntax error

Luka
  • 187
  • 3
  • 9
  • 4
    Are you using the python console or `Tkinter` or `pygame` or what? – sshashank124 Mar 29 '14 at 10:12
  • Oh I didn't know that was important, I just use notepad++ for writing the code, and then I save it as .py and open it with software I downloaded from python.org – Luka Mar 29 '14 at 10:15
  • Curses, if only there were a way to make colored terminal graphics like the old nethack game. – Paul Mar 29 '14 at 10:15
  • You can't I believe. Correct me if I'm wrong. You should look into `Tkinter` or `pygame`. High initial startup devotion but pays off in the long run. – sshashank124 Mar 29 '14 at 10:16
  • 1
    Here, this should help: http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python – Carsten Mar 29 '14 at 10:19
  • http://docs.python.org/2/howto/curses.html – Paul Mar 29 '14 at 10:22
  • Here's a [code example on how to print red circle in a terminal in random places](http://stackoverflow.com/a/22121542/4279) – jfs Mar 29 '14 at 10:49
  • 1
    @Paul: For colored output in a terminal, `blessings` (+ `colorama` for Windows) modules are much simpler and cleaner than curses. See [example I've linked above](http://stackoverflow.com/a/22121542/4279) – jfs Mar 29 '14 at 10:50

1 Answers1

1

Is this what you're looking for?
Print in terminal with colors using Python?
Basically, you do it by printing ANSI escape sequences.
For example:

print '\x1b[31mThis is sentence is red\x1b[m'

Community
  • 1
  • 1
amigcamel
  • 1,879
  • 1
  • 22
  • 36