我在樹莓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
添加代碼。輸入只在執行開始時執行,當我使用循環時窗口凍結。 –