python-3.x - 使用 PyQt 显示 Raspberry Pi GPIO 读数
问题描述
我正在做一个树莓派项目。Raspi 检测到激光光栅何时被中断。
发生这种情况时,我想更改 PyQt 标签中的文本。
我现在有两个 Python 文件,我不知道如何将它们连接在一起。
GPIO检测:
import RPi.GPIO as GPIO
import os, time
RECEIVER_PIN = 23
def callback_func(channel):
if GPIO.input(channel):
# CHANGE THE PYQT LABEL TEXT
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RECEIVER_PIN, GPIO.IN)
GPIO.add_event_detect(RECEIVER_PIN, GPIO.RISING, callback=callback_func, bouncetime=200)
try:
while True:
time.sleep(0.5)
except:
GPIO.remove_event_detect(RECEIVER_PIN)
和 PyQt 窗口:
import sys from PyQt5.QtWidgets import QApplication, QMainWindow from PyQt5.QtCore import QFile from ui_mainwindow import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.label.setGeometry(QtCore.QRect(0, 19, 831, 461))
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
我怎样才能将这些连接在一起?
解决方案
推荐阅读
- c# - Unity 项目升级:将项目从 Unity4 升级到 Unity5 构建时出现 Getcomponent 问题
- javascript - React.createElement("audio", ... 不工作?怎么了?
- android - Android中的弹跳球跳过速度
- google-analytics - 如何将 Google Analytics 片段插入我的 Mediawiki wiki 页面?
- c# - WPF 打包未能包含必要的第 3 方 DLL
- jquery - 在 jQuery 中循环相同的函数集
- reactjs - setState 回调在 React 16 中的渲染完成之前执行
- npm - “npm run build”只能从包含 package.json 文件的文件夹中运行吗?
- c# - 谷歌搜索按钮点击硒
- powershell - Windows 任务计划程序 Powershell 脚本完成并重新启动