有没有办法让用户输入而不必按Enter键? 我搜索了这个问题,但大部分答案都是针对Python 2的,或者不起作用。
我不明白,或者这个解决方案不起作用:How to accept input without the need to press enter Python 3
答案 0 :(得分:0)
您可以在Windows上使用msvcrt来允许用户输入一个值,然后输入它,而无需实际按回车键。
import msvcrt #You will need this.
your_variable = msvcrt.getch() #Allows the user to enter a single value,
#then immediately enter it.
侧面说明:您无法在Shell中正确运行此程序,只能直接从文件夹中运行它。 另外,如果您感到懒惰,可以使用我创建的here模块,如果使用它并发现任何错误,请告诉我,因为它可以帮助我更好地使用python。希望我能对您有所帮助!