Python Forum

Full Version: Receive Input on Same Line?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to receive input on the same line, without clearing the rest of the terminal?

The following prints a new "Enter" line for every bad entry.

while not entry in menu:
	entry = input('Enter: ')
You could use curses or termios if you aren't running on windows. There is a windows curses package, but I have not used it.

https://pypi.org/project/windows-curses/
(Jan-13-2024, 09:24 PM)johnywhy Wrote: [ -> ]How to receive input on the same line, without clearing the rest of the terminal?

I used Blessed for this project and I've had no reports that it does not work on a MS Windows OS, but maybe that's because no one has tried it. If you do try it, then maybe you could report back and let me know if it works okay for you? That's assuming that you are using a MS Windows OS; I know for sure that my app works fine on at least two Linux distros, and as I see no reason why it would fail to work on most (if not all) Linux distros.
(Jan-14-2024, 01:45 PM)deanhystad Wrote: [ -> ]There is a windows curses package, but I have not used it.
I believe ncurses is a python win lib.

(Jan-14-2024, 03:25 PM)rob101 Wrote: [ -> ]If you do try it, then maybe you could report back
I shall!
Seems to work in Win 10. I got stuck here, but i didn't really try to play the game. Just checking on the terminal features.

[Image: TgYS5YW2wYV4.png]

I'm wonder whether blessed is smaller than ncurses...
also, wondering if there's a way for python to install needed packages if not already installed
Quote:also, wondering if there's a way for python to install needed packages if not already installed
Users may (will) not appreciate your program loading a package into their pyhon distribution. A better idea is to display a message indicating why the game cannot run. You might also consider making a .exe file or writing your game as a tkinter app.
(Jan-15-2024, 10:53 PM)deanhystad Wrote: [ -> ]making a .exe file or writing your game as a tkinter app.
Yes, i'd prefer to bundle needed libs with my distribution. Glad to know python supports that!

I'm assuming you mention tkinter for GUI stuff. Good to learn about tkinter, When comes time to make a GUI, i will check out tkinter.

tho' in this question i'm only exploring terminal manipulation, in order to avoid making a GUI.
thx!
Thank you for reporting back: I'll post an update to the effect that you've run my app on MS Win 10, with no issues. I thought it would work, but as I don't have a MS Windows box, I could not test this for myself.

There's a conditional import for the Blessed library, which I prefer, rather than installing it behind a users back.

My first draft for this, was to code it in a Tkinter GUI, but it got way complicated, way quick, and I could not make it emulate the way that the Apple-1 game worked, which is why I dropped the idea and went with Blessed instead, which I found to be very nice to use and code with. The documentation is very good and as such, it did not take too long to suss it out and code the UI.

Once again, thank you.
(Jan-16-2024, 02:47 AM)rob101 Wrote: [ -> ]Tkinter GUI, but it got way complicated, way quick, and I could not make it emulate the way that the Apple-1 game worked, which is why I dropped the idea and went with Blessed instead, which I found to be very nice to use and code with.

Once again, thank you.

My pleasure.
Thank you for sharing that info.

I just learned the following, from one of the blessed team:

both blessed and urwid are wrappers around the ncurses library

blessed is a bit lower-level, best for making interactive games, like the example worms.py program or custom user interfaces like cursewords

urwid is a widget library, for making "windows" and dialog boxes, like in the mastadon client toot

the "curses" module that is built-in to python is a wrapper of the C library from the 1980's. It is cumbersome to use, as the example of the blessed README describes at the bottom.