How can you change the position of your input in python?

Viewed 47

I've read many other articles on here about how to move the position of the input, but I've only seen how to move it back. I tried using "\b" for this but it doesn't work, can anyone help? btw I'm using repl.it,I'm not sure what version of python it uses

choice=int(input("╒══════════╤══════════╤══════════╕\n"
                +"│1 - ATTACK│ 2 - HEAL │ 3 - FLEE │\n"
                +"╞══════════╧══════════╧══════╤═══╡\n"
                +"│ Enter your choice here --> │ X │\n"
                +"╘════════════════════════════╧═══╛"))
1 Answers

You can use ANSI escape codes to move the cursor around. The Wikipedia Page has a lot of good information about how they work, along with a table that contains all the relevant escape codes to help you.

import os
import msvcrt

# Make sure that ANSI codes work
os.system('')

# We will move 1 line up and to the 32nd column
go_to_X = "\033[F" + "\033[32G"

# Print the message and the escape sequence
# Use end="" so that Python does not add an extra newline at the end of the string
print("╒══════════╤══════════╤══════════╕\n"
    +"│1 - ATTACK│ 2 - HEAL │ 3 - FLEE │\n"
    +"╞══════════╧══════════╧══════╤═══╡\n"
    +"│ Enter your choice here --> │ X │\n"
    +"╘════════════════════════════╧═══╛" + go_to_X, end="")

# Read one character from STD input (getch = "Get char")
# If you are on linux, then use getch.getch()
choice=int(msvcrt.getche())
Related