0

I'm pretty new to programming, and I'm creating a simple text-based game.>

I'm wondering if there is a simple way to create my own terminal-type window with which I can place coloured input etc.

Is there a graphics module well suited to this? I'm using Mac, but I would like it to work on Windows as well

Thanks

mjv
  • 73,152
  • 14
  • 113
  • 156
  • 1
    You really should go GUI nowadays whenever you want to make games that are not line-based. It is possible to do that in console but setting the terminal buffering modes, drawing ANSI graphics and all that is just too complex, and you still won't be able to portably do things such as detect two keys being held down at the same time. With GUI all this is very easy. – Tronic Apr 03 '10 at 06:14
  • @Tronic: Is there a particular GUI module u can suggest? –  Apr 03 '10 at 06:52
  • For making games in Python, Pygame is probably the best option. – Tronic Apr 03 '10 at 19:17

3 Answers3

2

You could use the termcolor library - it that what you're looking for?

On Windows things are trickier. See this SO answer - you should resort to win32console and some ctypes. The answer has some code and links to other articles.

Community
  • 1
  • 1
Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
  • Conceptually the `termcolor` thing is uglier, imho. It's just that probably no one really bothered bringing the Windows console API to Python in a nicely usable way :-) – Joey Apr 03 '10 at 06:17
  • @Johannes: I suppose this is because on Windows terminals are far less useful than on other platforms – Eli Bendersky Apr 03 '10 at 06:26
  • They have a defined set of capabilities, making things like termcap and terminfo obsolete. And they have a C API instead of a text stream "API". That's about all the differences. All the nice things of ECMA-48 that extend beyond moving the cursor around or changing the color are nowhere implemented in terminal emulators anyway. – Joey Apr 03 '10 at 06:39
2

The Tkinter Text Widget will do what you ask. the IDLE main window is implemented as one, if you want to play with an example.

msw
  • 42,753
  • 9
  • 87
  • 112
1

For game programming with Python, I would always recommend PyGame. It is not very complex and enables you to easily use input, graphics and sound. As a start:

http://www.penzilla.net/tutorials/python/pygame/

hendrik
  • 121
  • 2