【问题标题】:How to enter a input without pressing enter [duplicate]如何在不按Enter的情况下输入输入[重复]
【发布时间】:2013-04-22 11:01:38
【问题描述】:

例如我想要这样,

x = int(input("Please enter your guess :")
If x = 1:
   Print ("correct")

虽然每次我需要按回车键,我怎样才能让它在按键时读取

我确实找到了 getch(),虽然我无法让它工作。

【问题讨论】:

标签: python python-3.x


【解决方案1】:

在 Windows 中,您可以使用 msvcrt。在其他系统上它有点困难,看看这个配方:http://code.activestate.com/recipes/134892/

你可以这样使用它:

getch = _Getch()

print 'Please enter your guess: '
x = getch()

if (int(x) == 1):
    print 'correct'
else:
    print 'wrong'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 2016-08-14
    • 2017-07-27
    • 1970-01-01
    相关资源
    最近更新 更多