Sharpfawkes
Sharpfawkes

Reputation: 569

How to explicitly move the cursor in python

I wanted to know if there was any way I could print a set of lines in Python and then move the cursor up or down to different locations. For example,
Output:
First Name         Last Name
Email Address
Password

If I printed the above lines, how would I able to move the cursor from after password to where it would usually be to, just after First Name so that the user could enter raw input to be stored in a specific variable.

Upvotes: 2

Views: 2655

Answers (1)

MaxNoe
MaxNoe

Reputation: 14997

Using the blessings library you could use this on unix systems:

from blessings import Terminal

t = Terminal()

with t.fullscreen():
    print('First Name:')
    print('Last Name:')
    print('Age:')

    firstname = input(t.move(0, 14))
    lastname = input(t.move(1, 14))
    age = input(t.move(2, 14))

Upvotes: 1

Related Questions