请仔细查看此块:
for i in range( buttons ):
button = joystick.get_button( i )
textPrint.print(screen, "Button {:>2} value: {}".format(i,button) )
textPrint.print
使用按钮ID绘制文本(
i
)及其声明(
button
)(释放0,按下1)。因此,如果您需要在按下按钮时打印一些文本,只需添加以下内容:
if button == 1:
print("Button "+str(i)+" is pressed")
到街区去,它应该会起作用。
顺便说一句,你可以使用
我
(按钮ID)以在if语句中使用。
if button == 1:
if i == 2:
print("A is pressed")
elif i == 1:
print("B is pressed")
这就是街区的样子:
for i in range( buttons ):
button = joystick.get_button( i )
if button == 1:
if i == 2:
print("A is pressed")
if i == 1:
print("B is pressed")
textPrint.print(screen, "Button {:>2} value: {}".format(i,button) )