简体   繁体   中英

Underlining user input in python3

I was wondering how I can set up my program whereby the user input is underlined without having to import a different system. I have an idea to use my own class as follows:

class Colors:

    underline = '\033[04m'

but I am stuck because I don't know how to reflect that on user input

the part underlined is what the user has to input

This should work:

input('User input: \033[4m\0')

EDIT - end the underlining

This works on mine. The 'end' parameter is just so the print does not change the line.

input('User input: \033[4m\0')
print('\033[0m', end='')
input('User input: \033[4m\0')
print('\033[0m', end='')
input('User input: \033[4m\0')

Using your colors class scheme:

class Colors:

    start_underline='\033[04m'
    end_underline = '\033[0m'


a = input('Enter the project name: ')
print (Colors.start_underline + '{}'.format(a) + Colors.end_underline)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM