A portable way to read a single character from the keyboard??

timin at homeSPAMNOT.com timin at homeSPAMNOT.com
Sun Sep 10 10:21:53 EDT 2000


An alternate approach is to use Tkinter to make a window with a group of
labeled buttons.  That will give you the functionality you want using buttons
rather than keys, and it will be portable, and more attractive to the eye than
the command line approach.

m

Matthew Dixon Cowles wrote:

> On Sun, 10 Sep 2000 00:03:06 +0200, Iwan van der Kleyn
> <ivdkleyn at xs4all.nl> wrote:
>
> >I want to implement a simple console-menu. The script needs to read
> >single characters from the keyboard. In this way the user only needs
> >to press a sinle character in order for a function to be
> >performed. Under WIndows you can use the msvcrt module in the
> >following way:
>
> [...]
>
> >However, this method is not portable. It cannot be used under Linux
> >for example. What would be the portable equivalant? I've tried
> >sys.stdin.read(1), but this function insists on blocking the system
> >until ENTER is pressed.
>
> Iwan,
> Unfortunately, there's no portable way to do what you want despite the
> fact that many people would like there to be. Have a look at
>
> http://www.python.org/doc/FAQ.html#4.74
>
> for the best advice that's on offer. You could use sys.platform to
> decide what routine to call.
>
> Regards,
> Matt




More information about the Python-list mailing list