【问题标题】:UI and hardware ButtonUI 和硬件按钮
【发布时间】:2019-07-16 23:41:03
【问题描述】:

我想从连接到 Raspberry 的 Switch(test) 调用一个函数。使用下面发布的代码,当我单击 UI 上的按钮时,函数(asdf)正在运行。我删除了所有其他内容以使其看起来清晰。 但是当 GPIO 为 LOW 时如何调用(测试)函数?

import RPi.GPIO as GPIO
from tkinter import *
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(20,GPIO.IN)  # If Button is not pressed, Signal is HIGH
fenster = Tk()
fenster.geometry("100x100")


def test():
    if(GPIO.input(20)==False): 
        print("a")

def asdf():
    print("asdf")

b3=Button(fenster,text ="Referenzfahrt", command=asdf)
b3.config()
b3.pack(side="top")


fenster.mainloop()

【问题讨论】:

    标签: tkinter raspberry-pi gpio


    【解决方案1】:

    我解决了:

    GPIO.add_event_detect(20, GPIO.RISING, callback=lambda x: test(), bouncetime=1000)
    

    当我按下按钮时,它会调用该函数

    【讨论】:

      猜你喜欢
      • 2017-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多