[Tutor] Curses example on Linux?
Hossein Movahhedian
dma8hm1956 at gmail.com
Mon Aug 8 16:54:50 CEST 2005
Hi All,
I have copied the following example from "Learning to Program by Alan
Gauld (section: Event Driven Programming)". To run it on Linux
(Redhat 8.0; Python 2.4) the tutorial says to replace 'msvcrt'
with 'curses.stdscr'. But there is no stdscr method in curses.
In fact with 'import curses.stdscr' I get the following error message::
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named stdscr
How should I modify it for Linux?
Thanks in advance,
Hossein
The example:{{{
import msvcrt
def doKeyEvent(key):
if key == '\x00' or key == '\xe0': # non ASCII
key = msvcrt.getch() # fetch second character
print ord(key)
def doQuitEvent(key):
raise SystemExit
# First, clear the screen of clutter then warn the user
# of what to do to quit
lines = 25 # set to number of lines in console
for line in range(lines): print
print "Hit space to end..."
print
# Now mainloop runs "forever"
while True:
ky = msvcrt.getch()
length = len(ky)
if length != 0:
# send events to event handling functions
if ky == " ": # check for quit event
doQuitEvent(ky)
else:
doKeyEvent(ky)
}}}
More information about the Tutor
mailing list