python - 树莓派与Python

标签 python python-3.x raspberry-pi raspberry-pi3

我有一个连接到 2x16 LCD 和数字键盘的树莓派。我的问题是,除非按 Enter 键,否则我看不到正在输入的数字。有什么解决方案可以让我输入数字并显示出来吗?我尝试过诅咒和线程但没有运气 强调文字

import lcddriver
display = lcddriver.lcd()

try:
    display.lcd_display_string('Room Number:',1)
    room = input()
    display.lcd_display_string(str(room),2)

except KeyboardInterrupt:
    display.lcd_clear()

最佳答案

您的代码使用内置函数input,它仅在您按 Enter 时接收输入,它不会(也无法)读取每个击键。

您可以使用inputsevdev库来跟踪击键并在按下键时立即采取行动,而不是等待输入整个字符串。

关于python - 树莓派与Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55156422/

相关文章:

python - 将列表转换为多值字典

c++ - 树莓派uart波特率锁定在9600

android - 带有 Android 东西的 Raspberry Pi 3 上的屏幕方向

python 使用列表理解或其他方法将列表中的 None 替换为空白?也是嵌套列表解决方案

python - 如何找到两个特殊字符之间的字符串?

python 3 : Conditional extraction of keys from a dictionary with comprehension

python - 在 [Errno 32] Broken pipe 的情况下,Python 3.2 抛出什么样的异常

java - 服务器异常: The connection implementation for btspp cannot be found

python - Pandas 数据帧 : Remove row satisfying certain condition

python - 如何在 aws 中使用 boto3 创建不具有公共(public)访问权限的存储桶和对象?