Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Receive Input on Same Line?
#1
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: ')
Reply
#2
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/
johnywhy likes this post
Reply
#3
(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.
johnywhy and Gribouillis like this post
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#4
(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!
Reply
#5
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
Reply
#6
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.
Reply
#7
(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!
Reply
#8
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.
johnywhy likes this post
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#9
(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.
rob101 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 359 Feb-17-2024, 12:29 PM
Last Post: deanhystad
  How to continuously receive messages until specified to stop using Bleak jacobbreen25 3 2,159 Dec-28-2022, 04:25 PM
Last Post: jacobbreen25
  How can I add an end line character after every value that I receive? GiggsB 11 5,203 Mar-06-2022, 08:51 PM
Last Post: GiggsB
  How to receive webcam capture on spout? buzzdarkyear 2 2,671 Jan-12-2022, 02:26 PM
Last Post: buzzdarkyear
  How to input & output parameters from command line argument shantanu97 1 2,584 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 3,354 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  Multi-line console input lizze 4 2,382 Dec-26-2020, 08:10 AM
Last Post: lizze
  bad input line 3 how t fix it youssef210 2 2,717 Aug-27-2020, 04:57 PM
Last Post: nilamo
  Line charts error "'isnan' not supported for the input types," issac_n 1 2,421 Jul-22-2020, 04:34 PM
Last Post: issac_n
  Taking Multiple Command Line Argument Input bwdu 6 4,068 Mar-29-2020, 05:52 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020