William Sys
William Sys

Reputation: 1

How to print text behind an input in python 3.x

Sorry the title is confusing, but i'm not too sure how to word it appropriately.

My goal here is to have regular python input but for text for the input to be displayed to the right of where i'm typing.

For example what the user would see:

                          <- input your age

i'm looking for the cursor and where they type to be in that blank space, where the arrow is pointing.

Is this possible or am I being an idiot here?

Sorry if this is confusing or if I have worded this badly,

thankyou for your time.

Upvotes: 0

Views: 426

Answers (2)

joshmeranda
joshmeranda

Reputation: 3261

The simplest way to achieve this is to use the carriage return (CR) ascii escape sequence. The "\r" character ill move the cursor t the beginning of the current line and begin taking input. Be careful with the amount of white space you have in the prompt since long names will begin to overwrite the prompt itself.

Note that as in @Carcigenicate's comment this will not work in every terminal or my behave differently.

name = input("                          <- input your age\r")

Upvotes: 1

jarmod
jarmod

Reputation: 78842

Try the python-prompt-toolkit package.

In particular, the Adding a right prompt section.

enter image description here

Upvotes: 0

Related Questions