At the easy risk of asking something already asked a hundred times...
Curses doesn't work for me.
I use 2.6 on a Vista
It gives an error saying it can't call up a part of the module that came with the program.
... Uhm... help.. T_T
~Pixel

At the easy risk of asking something already asked a hundred times...
Curses doesn't work for me.
I use 2.6 on a Vista
It gives an error saying it can't call up a part of the module that came with the program.
... Uhm... help.. T_T
~Pixel

You had 2 bad ideas:
1) use vista
2) use curses
Anyway, let's have a look. What's the exception traceback ? (between code tags please)

You had 2 bad ideas:
1) use vista
2) use curses
Anyway, let's have a look. What's the exception traceback ? (between code tags please)

My school is using Vista, not my fault.
Give me one moment to call up the program...

Traceback (most recent call last):
  File "S:\Bell Work\ColorOutput.py", line 17, in <module>
    import curses
  File "C:\Python26\lib\curses\__init__.py", line 15, in <module>
    from _curses import *
ImportError: No module named _curses

... It won't even import curses. Heck.
Do you have something I -can- use to work with color? So far only curses works for color output of text.

... It won't even import curses.

That's because curses isn't available for Windows. The documentation should probably specifically say that, but they actually just tip-toe around that fact:

The curses module provides an interface to the curses library, the de-facto standard for portable advanced terminal handling.

While curses is most widely used in the Unix environment, versions are available for DOS, OS/2, and possibly other systems as well. This extension module is designed to match the API of ncurses, an open-source curses library hosted on Linux and the BSD variants of Unix.

[Source = PyDocs]

Is your instructor asking you to use curses? Or are you just doing it to be snazzy?

If you're really insistent on using it you'll need to use either unix or dos or some other compatible platform.

An entry in the Python26 manual:
No one has made a Windows port of the curses module. On a Windows platform, try the Console module written by Fredrik Lundh. The Console module provides cursor-addressable text output, plus full support for mouse and keyboard input, and is available from http://effbot.org/zone/console-index.htm.

It's much easier to use a gui interface like wxpython than writing a program with curses. If you want to output text, wxpython has widgets that can do it very well.

That's because curses isn't available for Windows. The documentation should probably specifically say that, but they actually just tip-toe around that fact:[Source = PyDocs]

Is your instructor asking you to use curses? Or are you just doing it to be snazzy?

If you're really insistent on using it you'll need to use either unix or dos or some other compatible platform.

I'm doing it because it's the only thing I can find that would allow for what I want. I'm to write a program that allows the user to input what color he wants his input to print out in, then input what he wants...
And when you say compatible platform... uhm... whuh???

It's much easier to use a gui interface like wxpython than writing a program with curses. If you want to output text, wxpython has widgets that can do it very well.

Uhm... wait, difference between wxpython and python are what?...
.... crap, now I'm so confused...

And when you say compatible platform... uhm... whuh???

The platform can be simplified to mean your operating system. If you load up a python interpreter try the following exercise:

>>> import sys
>>> sys.platform
'win32'
>>> import curses
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python26\lib\curses\__init__.py", line 15, in <module>
    from _curses import *
ImportError: No module named _curses
>>>

This was done on a windows box. You can see that my platform is win32, which is not a compatible platform for curses (without some type of third-party library, which may not even exist). Now let's try the same thing on a red hat box:

>>> import sys
>>> sys.platform
'linux2'
>>> import curses
>>>

Now on red hat linux (a unix-based OS, which is compatible with curses) the import works just fine.

Uhm... wait, difference between wxpython and python are what?...
.... crap, now I'm so confused...

wxPython is a GUI framework build around the wx.Windows library, which is used to build application GUIs. It's basically a module that you can import into your python programs that opens up a whole new world of options for you when designing your programs. You can find the wx website here, and there's a bajillion code examples of different GUI elements in this thread here (you'll find it as a sticky at the top of this Python forum).

Hope that you find something that works for you. Good luck!

The platform can be simplified to mean your operating system. If you load up a python interpreter try the following exercise:

>>> import sys
>>> sys.platform
'win32'
>>> import curses
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python26\lib\curses\__init__.py", line 15, in <module>
    from _curses import *
ImportError: No module named _curses
>>>

This was done on a windows box. You can see that my platform is win32, which is not a compatible platform for curses (without some type of third-party library, which may not even exist). Now let's try the same thing on a red hat box:

>>> import sys
>>> sys.platform
'linux2'
>>> import curses
>>>

Now on red hat linux (a unix-based OS, which is compatible with curses) the import works just fine.

wxPython is a GUI framework build around the wx.Windows library, which is used to build application GUIs. It's basically a module that you can import into your python programs that opens up a whole new world of options for you when designing your programs. You can find the wx website here, and there's a bajillion code examples of different GUI elements in this thread here (you'll find it as a sticky at the top of this Python forum).

Hope that you find something that works for you. Good luck!

1. So you're saying I'm not going to be using curses ever in my life unless I get a linux?... crap...

2. If you mean IDLE, I'm using IDLE. I think I saw wxpython somewhere in the program files... but we call it IDLE, so... yeah...

... Damnations, this is getting really confusing.
Not to mention frustrating. All my other programs work but that one, and it's only because of an import error, the code itself -should- work.. in fact... I need someone to test that...

Complete with all the comments made for the teacher, too!

# ... go me for trying to use curses. Of course, it doesn't work in Python 2.6.
# Why would it work in 2.6? I want it to work in 2.6.
# Thus, it's not going to work... *sigh* I suppose this was going to happen...
# If curses actually worked for 2.6, I'm almost positive it would have worked overall.
# ... also, I'm beginning to use time.sleep a LOT more often.
# It's niiice. ^^;
# ... Yay I'm rambling again... I have the solution.
# from toolbox import duct_tape
# def shutup(person):
#     mouth.append(duct_tape)
# shutup(self)
# ...
# I am officially a programming nerd for that... And now for the failured code.


import time
import curses
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
start_color()

print "This is a very volatile machine you are about to run."
time.sleep(2)
print "Changing the colors of items in this universe is a very dangerous action."
time.sleep(3)
print "If this device you are about to use implodes, we are not responsible."
time.sleep(2.5)
print "This is your official warning."
time.sleep(1)
print "The Python/ACME Corporation cannot and will not take responsibility"
print "for damages that occur from use of this mechanism."
time.sleep(4)
print "Thank you for your patronage, and we hope you stay safe."
time.sleep(3)

black = 0
red = 1
green = 2
yellow = 3
blue = 4
magenta = 5
cyan = 6
white = 7
colorList = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']
playAgain = 'yes'

while playAgain == 'yes' or playAgain == 'y':
    print "Generating the list of available colors..."
    time.sleep(3)
    for color in colorList:
        print color
        time.sleep(.25)
    time.sleep(.75)
    colorChoice = input("Please select a color from this list. ")
    print "Preparing the text for colorization..."
    time.sleep(3)
    textToColorize = raw_input("Please type in what you want to say in the new color: ")
    print "Now attempting to colorize..."
    time.sleep(3)
    stdscr.addstr(textToColorize, curses.color_pair(colorChoice))
    playAgain = raw_input("Do you wish to go again? ")

Also, uhm, don't chew me out for the programming joke and anything that doesn't make sense, I was trying to shut myself up.
If you haven't noticed, that seems to be a problem for me. >.<

1. So you're saying I'm not going to be using curses ever in my life unless I get a linux?... crap...

Unless you run your script on a compatible platform, you will not be able to experience the joy of curses, no. If you're on windows you can either download and burn a linux live CD to boot from (this doens't require installing linux), or you could install cygwin. This program is basically an emulated version of linux; however it will allow you to at least play around with curses and a few linux commands to get used to it.

2. If you mean IDLE, I'm using IDLE. I think I saw wxpython somewhere in the program files... but we call it IDLE, so... yeah...

No, IDLE is your IDE (environment to develop your code). wxPython is a module that you would import. The packages within wxPython allow you to develop a GUI for an application. wxPython is not included with Python, it's a separate install. Take a look at the sticky thread in this forum for some examples of using wxPython and the results that it can give.

the code itself -should- work.. in fact... I need someone to test that...

It does not work, unfortunately.

I think you may be confused about how curses works. Curses isn't just a library that allows you to play with how stdout is put on the screen, it's almost like an entire platform. There's literally books on how to use it, and it can be extremely complex. It's basically a way to build a text-based GUI. So in ways it's similar to wxPython, except it's terminal/text based instead of window based, if that makes sense.

Once you initscr you are no longer working with the standard input/output methods of python. The screen is completely in your control and you've got to modify every single character on screen manually (more or less). This means your print statements won't work reliably. What you should be using is stdscr.addch or stdscr.addnstr , stdcsr.overwrite , etc., etc. Refer to the documentation on window objects (what is returned from initscr() , which in your case is stdscr) for more information on how to manipulate and control the screen.

Also, it's extremely important to relenquish control of the screen back to the system when you're done playing with curses or else the stdout will be seriously borked. When I first ran your program I had to completely kill my terminal window because you never did this step. So the final thing that runs in your program should be stdscr.endwin() . Also, when your program does run, nothing happens. Well, I mean it's happening behind the scenes, but nothing is displayed onscreen because the stdout is never "flushed". In curses this is done by issuing a refresh to your window object. Anyway, if you're insistent on using curses I suggest downloading and installing cygwin to play arround with it. Also read up on the documentation and look online for examples of proper ways to handle the input/output of the screen.

Good luck.

Edited 7 Years Ago by jlm699: n/a

Unless you run your script on a compatible platform, you will not be able to experience the joy of curses, no. If you're on windows you can either download and burn a linux live CD to boot from (this doens't require installing linux), or you could install cygwin. This program is basically an emulated version of linux; however it will allow you to at least play around with curses and a few linux commands to get used to it.

No, IDLE is your IDE (environment to develop your code). wxPython is a module that you would import. The packages within wxPython allow you to develop a GUI for an application. wxPython is not included with Python, it's a separate install. Take a look at the sticky thread in this forum for some examples of using wxPython and the results that it can give.

It does not work, unfortunately.

I think you may be confused about how curses works. Curses isn't just a library that allows you to play with how stdout is put on the screen, it's almost like an entire platform. There's literally books on how to use it, and it can be extremely complex. It's basically a way to build a text-based GUI. So in ways it's similar to wxPython, except it's terminal/text based instead of window based, if that makes sense.

Once you initscr you are no longer working with the standard input/output methods of python. The screen is completely in your control and you've got to modify every single character on screen manually (more or less). This means your print statements won't work reliably. What you should be using is stdscr.addch or stdscr.addnstr , stdcsr.overwrite , etc., etc. Refer to the documentation on window objects (what is returned from initscr() , which in your case is stdscr) for more information on how to manipulate and control the screen.

Also, it's extremely important to relenquish control of the screen back to the system when you're done playing with curses or else the stdout will be seriously borked. When I first ran your program I had to completely kill my terminal window because you never did this step. So the final thing that runs in your program should be stdscr.endwin() . Also, when your program does run, nothing happens. Well, I mean it's happening behind the scenes, but nothing is displayed onscreen because the stdout is never "flushed". In curses this is done by issuing a refresh to your window object. Anyway, if you're insistent on using curses I suggest downloading and installing cygwin to play arround with it. Also read up on the documentation and look online for examples of proper ways to handle the input/output of the screen.

Good luck.

... so it's like pygame or soemthing?
I personally dislike pygame. Too many useless bits of code to do one little thing, then a hundred more to do what text can often do quite easily. But that's just me, so...

And I'm not insistent on using curses by any means, just that it's the only way I could do what my teacher asked me to do, at least that I could find.

... Meh, she gave me a 100% grade on that assignment, I shouldn't really complain. >.>;

PS: Wow it's been a while since I was able to get on here.

This question has already been answered. Start a new discussion instead.