Reputation:
I would like to have an input loop in python 3 where the information which gets typed in gets deleted from terminal automatically (f.eks. after 3 seconds) I know the function with \r to go back in line, but struggle with the automatic new line after input.
while True:
inputStr = (input("Add the hidden word: ")).lower()
processingTheInput(inputStr) #some sort of function using the input word
Upvotes: 2
Views: 5634
Reputation: 1500
Ansi escape codes will not work the same on all terminals but this might suit your needs. The ‘\033’ is the escape character. The ‘[1A’ says go up one line and the ‘[K’ says erase to the end of this line.
prompt = 'Add the hidden word: '
inputStr = input(prompt).lower()
print ('\033[1A' + prompt + '\033[K')
Upvotes: 3
Reputation: 2607
You want to clear the terminal with a function
# import only system from os
from os import system, name
# import sleep to show output for some time period
from time import sleep
# define our clear function
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
Now you need to have a function that adds your word into a list then runs the clear function, then finally can pick a word at the end
Upvotes: 0