Sujet : RE: Tools to help with text mode (i.e. non-GUI) input
De : learn2program (at) *nospam* gmail.com (Alan Gauld)
Groupes : comp.lang.pythonDate : 13. Jan 2025, 23:46:19
Autres entêtes
Message-ID : <mailman.68.1736808383.2912.python-list@python.org>
References : 1 2
User-Agent : Mozilla Thunderbird
On 11/01/2025 14:28, Chris Green via Python-list wrote:
I'm looking for Python packages that can help with text mode input,
The standard package for this is curses which comes as part
of the standard library on *nix distros.
What I'm specifically after is a way to provide a default value that
can be accepted or changed easily and also a way to provide a number
of different values to choose from.
The default value is easy. The list of values sounds like a pop-up menu.
Ofr you can just offer a prompt with a list in it that the user
picks(maybe by number?) Its really a programmers choice, curses provides
the tools to display it however you choose. (Yu might also find the
dialog third party package useful for displaying text mode dialog boxes)
I.e. for the default sort of input one might see:-
Colour? red
Hitting return would return 'red' to the program but you could also
backspace over the 'red' and enter something else. Maybe even better
would be that the 'red' disappears as soon as you hit any key other
than return.
All of that is possible in curses, you just have to code it.
For the select a value type of input I want something like the above
but hitting (say) arrow up and arrow down would change the value
displayed by the 'Colour?' prompt and hitting return would accept the
chosen value.
Again that's easy enough to do. Or you could pop up a menu and
allow the user to cursor up/dowmn (or use the mouse) to select
an option.
In addition I want the ability to narrow down the list
by entering one or more initial characters, so if you enter 'b' at the
Colour? prompt the list of values presented would only include colours
starting with 'b' (beige, blue, black, etc.)
Again that's more about the programmer's use of the tools. curses
allows you to display the characters wherever/however you want
on screen.
Are there any packages that offer this sort of thing? I'd prefer ones
from the Debian repositories but that's not absolutely necessary.
It might also be possible/useful to use the mouse for this.
curses dores all you want but you need to do all the logic, its not as
simple as using a GUI toolkit. dialog sits on top of curses and provides
a more GUI like experiece.
urwin is another toolkit for text mode but it is more of a pseudo GUI
environment with a menu-bar, dialogs, forms etc etc. Curses is about
mapping areas of the screen(windows) and displaying text within those
areas. You can control colour and strength etc, move things around,
hide/show areas, position the cursor anywhere on screen. You can even
create huge virtual screens and use the visible screen as a viewport
into that(think like a big spreadsheet)
There are a couple of Howto type documents online
Shameless Plug:
---------
I wrote a short kindle book on curses with python:
https://kdp.amazon.com/amazon-dp-action/us/dualbookshelf.marketplacelink/B091B85B77-------------
HTH
-- Alan GAuthor of the Learn to Program web sitehttp://www.alan-g.me.uk/http://www.amazon.com/author/alan_gauldFollow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos