我在树莓pi3上制作了一个gui程序,我想从输入(gpio)中获取信号来执行一些命令,例如按下按钮时生成一个信号。 我想从输入中得到这个信号。 代码是在gtk3,python,raspberry中创建输入信号
import time
import gi
import RPi.GPIO as GPIO
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.IN,pull_up_down=GPIO.PUD_DOWN)
class gui:
inputValue = GPIO.input(18)
if inputValue == True:
self.label.set_text("There is input")
def on_window1_destroy(self, object, data=None):
print("quit with cancel")
Gtk.main_quit()
def on_okButton_clicked(self,button,data=None):
self.label.set_text("Waiting for input")
def __init__(self):
self.gladefile = "2.glade"
self.builder = Gtk.Builder()
self.builder.add_from_file(self.gladefile)
self.builder.connect_signals(self)
self.window = self.builder.get_object("window1")
self.label = self.builder.get_object("Label")
self.label.set_text("Hello")
self.window.show_all()
if __name__ == "__main__":
main = gui()
Gtk.main()
输入仅在执行的开始被取和,当我使用一个循环的窗口冻结。 请帮助我。 谢谢。
你有什么代码?你有没有读过像[这里]的教程(http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-2)? – theGtknerd
添加代码。输入只在执行开始时执行,当我使用循环时窗口冻结。 –