【发布时间】:2017-12-18 09:02:31
【问题描述】:
from pad4pi import rpi_gpio
# Setup Keypad
KEYPAD = [
["1","2","3","A"],
["4","5","6","B"],
["7","8","9","C"],
["*","0","#","D"]
]
ROW_PINS = [5,6,13,19] # BCM numbering
COL_PINS = [26,16,20,21] # BCM numbering
factory = rpi_gpio.KeypadFactory()
keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
def processKey(key):
print("enter 3 digit")
print(key)
if key == 123:
print("correct")
else:
print("wrong password")
keypad.registerKeyPressHandler(processKey)
我希望代码等待用户输入例如 3 位数字,然后再与上面代码中的 123 代码中的密码进行比较。
应该怎么做:
等待用户从键盘输入 3 位数字,例如 123,然后打印正确。
实际作用:
用户输入1位密码后会立即打印正确或错误的密码
【问题讨论】:
-
检查
if len(key) == 3:但你必须将key保留在全局值中并附加新字符。
标签: python python-2.7