如何运行仅在用户输入期间显示命令提示符的python脚本?

问题描述 投票:1回答:1

我有一个python script,其中有一个user inputval = input("Enter a name ?")我需要执行它以隐藏命令提示符在用户输入时显示它,然后再次在用户输入后隐藏它如何使用python实现它?我尝试将其重命名为.pyw,但是没有用。谁能帮忙?

python python-3.x python-2.7 pywin32
1个回答
0
投票

您可以使用键盘模块检查用户按下任何键并显示您的输入的天气:

pip install keyboard
import keyboard  # using module keyboard
while True:  # making a loop
    try:  # used try so that if user pressed other than the given key error will not be shown
        letters='abcdefghijklmnopqrstuvxyz'
        if any(keyboard.is_pressed(x) for x in letters):  # if any key is pressed
            print('You Pressed A Key!')
            break  # finishing the loop
    except:
        print("other key")
        break  # if user pressed a key other than the given key the loop will break

但是,如果要在等待输入时进行处理,则需要一个附加线程。

您还可以使用系统调用最后清除屏幕:

import os
os.system('cls')
© www.soinside.com 2019 - 2024. All rights reserved.