为了账号安全,请及时绑定邮箱和手机立即绑定

主文件PyQt4中的外部功能

主文件PyQt4中的外部功能

PIPIONE 2021-04-29 17:57:34
我非常努力地使此代码起作用。我尝试使用Qtimer,proccesEvents,但没有想要的结果。GUI启动,因此可以正常工作,但是没有任何更改,因此read()方法不起作用。我在stackoverflow上进行了大量搜索以寻求帮助,但找不到。也许我没有能力。这是代码:import RPi.GPIO as GPIOimport MFRC522import signalimport timefrom PyQt4 import QtCore, QtGuifrom ui_mainwindow import Ui_MainWindowclass MainWindow(QtGui.QWidget):    def __init__(self, parent=None):        QtGui.QWidget.__init__(self, parent)        self.ui = Ui_MainWindow()        self.ui.setupUi(self)    def reading(self):        self.ui.processEvents()        ### Event Functions ###        continue_reading = True        # Hook the SIGINT        signal.signal(signal.SIGINT, end_read)        # Create an object of the class MFRC522        MIFAREReader = MFRC522.MFRC522()        # This loop keeps checking for chips. If one is near it will get the UID and authenticate        while continue_reading:            # Scan for cards                (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)            # Get the UID of the card            (status,uid) = MIFAREReader.MFRC522_Anticoll()            # If we have the UID, continue            if status == MIFAREReader.MI_OK:                # This is the default key for authentication                key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]                # Select the scanned tag                MIFAREReader.MFRC522_SelectTag(uid)                # Authenticate                status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 8, key, uid)                # Check if authenticated                if status == MIFAREReader.MI_OK:                    MIFAREReader.MFRC522_Read(8)                    self.ui.label_3.show()                    self.ui.label_2.show()                    self.ui.label_4.show()                    self.ui.groupBox.setStyleSheet(_fromUtf8("background: white;\n"                    "border-style: solid;\n"                    "border-width: 1px;\n"                    "border-radius: 20px;"))
查看完整描述

2 回答

?
白衣染霜花

TA贡献1796条经验 获得超10个赞

您从不调用函数reading()吗?那么为什么要去那里呢?


我不确定您要实现什么目标,但是您可以尝试:


def __init__(self, parent=None):

    QtGui.QWidget.__init__(self, parent)


    self.ui = Ui_MainWindow()


    self.ui.setupUi(self)


    self.reading() ####################

但这只会调用一次函数。您什么时候reading()要执行?


查看完整回答
反对 回复 2021-05-11
  • 2 回答
  • 0 关注
  • 143 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信