weixin_40005331
weixin_40005331
采纳率0%
2019-08-08 21:48 阅读 1.4k

pyqt5如何弹出多个界面心事多组不同的数据

我这里有多组数据需要展示,展示的界面是在alert.py中写的,现在我想弹出多个界面,其中每个界面展示一组数据。现在的结果是alert.py可以接收到传过来的数据,界面也能弹出,但是界面上没有显示出数据,而且我的弹框线程无法将数据和界面一一对应起来,我想请问一下这是什么原因?

main.py

        from PyQt5 import *
        from PyQt5.QtGui import *
        from PyQt5.QtCore import *
        from PyQt5.QtWidgets import *
        import sys
        import time
        from alert import Show_Text
        from change import Show_Change
        import winsound



        class Ui_Control_system(object):



                def setupUi(self, Control_system):

                        Control_system.setObjectName("Control_system")
                        Control_system.resize(1004, 722)
                        Control_system.setFixedSize(1004, 722)

                        Control_system.setWindowIcon(QIcon('images/icon.png'))
                        Control_system.setStyleSheet("QMainWindow{border-image:url(images/background.jpg)}")

                        self.centralwidget = QWidget(Control_system)
                        self.centralwidget.setObjectName("centralwidget")

                        self.pushButton_skip = QPushButton(self.centralwidget)
                        self.pushButton_skip.setGeometry(QRect(70, 60, 121, 41))
                        self.pushButton_skip.setObjectName("pushButton_skip")

                        Control_system.setCentralWidget(self.centralwidget)
                        self.statusbar = QStatusBar(Control_system)
                        self.statusbar.setObjectName("statusbar")
                        Control_system.setStatusBar(self.statusbar)


                        self.retranslateUi(Control_system)
                        QMetaObject.connectSlotsByName(Control_system)


                def retranslateUi(self, Control_system):
                        _translate = QCoreApplication.translate
                        Control_system.setWindowTitle(_translate("Control_system", "实时监控系统"))

                        self.pushButton_skip.setText(_translate("Control_system", "跳转"))


        class Control_system(QMainWindow, Ui_Control_system):

                #alarmQueue = queue.LifoQueue()

                def __init__(self, parent=None):
                        super().__init__(parent)
                        self.setupUi(self)
                        self.add_data_list = ""
                        self.pushButton_skip.clicked.connect(self.jump_to_alert)
                        self._alerts = []


                @pyqtSlot()
                def jump_to_alert(self):    
                        self.popup_window_thread = PopupWindow(self)
                        self.popup_window_thread.popup.connect(self.goAlert)            
                        self.popup_window_thread.start()

                @pyqtSlot()
                def jump_to_change(self):    
                        self.change_window_thread = ChangeWindow(self)
                        self.change_window_thread.change_signal.connect(self.goChange)            
                        self.change_window_thread.start()

                def goAlert(self):                                                  

                        self.add_data_list = [["1","2","3"],["4","5","6"]]

                        for term in self.add_data_list:
                                alert = Alert()
                                alert.some_room = term[0]
                                alert.some_machine = term[1]
                                alert.some_project = term[2]
                                print(alert.some_project)
                                alert.show() 
                        self._alerts.append(alert)


        class Alert(Show_Text):

                def __init__(self):

                        super().__init__()
                        #self.setupUi(self)


                def closeEvent(self, event):

                        reply = QMessageBox.question(self,     '警告',
                                                                                                    "是否要退出警告?",
                                                                                                    QMessageBox.Yes | QMessageBox.No,
                                                                                                    QMessageBox.No)
                        if reply == QMessageBox.Yes:
                                event.accept()
                        else:
                                event.ignore()

        class PopupWindow(QThread): 

                popup = pyqtSignal()

                def __init__(self, parent=None):

                        super(PopupWindow, self).__init__()
                        self.index = 0

                def run(self):

                        while self.index <= 1:
                                self.index +=1
                                self.popup.emit()
                                time.sleep(1)

                def stop(self):  
                        self.quit()
                        self.wait()

        if __name__ == '__main__':

                if not QApplication.instance():
                        app = QApplication(sys.argv)
                else:
                        app = QApplication.instance() 

                w = Control_system()

                w.show() 
                sys.exit(app.exec())

alert.py

from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import time

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(557, 444)
        #Dialog.setStyleSheet("QDialog{border-image:url(images/background.jpg)}")
        Dialog.setWindowIcon(QIcon('images/icon.png'))
        self.textBrowser = QtWidgets.QTextBrowser(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(200, 80, 256, 41))
        self.textBrowser.setObjectName("textBrowser")
        self.textBrowser_2 = QtWidgets.QTextBrowser(Dialog)
        self.textBrowser_2.setGeometry(QtCore.QRect(200, 170, 256, 41))
        self.textBrowser_2.setObjectName("textBrowser_2")
        self.textBrowser_3 = QtWidgets.QTextBrowser(Dialog)
        self.textBrowser_3.setGeometry(QtCore.QRect(200, 260, 256, 41))
        self.textBrowser_3.setObjectName("textBrowser_3")
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(60, 80, 111, 31))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setStyleSheet("color: rgb(255, 0, 0);")
        self.label.setTextFormat(QtCore.Qt.AutoText)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(60, 170, 111, 31))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("color: rgb(255, 0, 0);")
        self.label_2.setTextFormat(QtCore.Qt.AutoText)
        self.label_2.setObjectName("label_2")
        self.alert = QtWidgets.QLabel(Dialog)
        self.alert.setGeometry(QtCore.QRect(60, 260, 111, 31))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.alert.setFont(font)
        self.alert.setStyleSheet("color: rgb(255, 0, 0);")
        self.alert.setTextFormat(QtCore.Qt.AutoText)
        self.alert.setObjectName("alert")

        self.retranslateUi(Dialog)


    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "警告"))
        self.label.setText(_translate("Dialog", "报警车间"))
        self.label_2.setText(_translate("Dialog", "报警机器"))
        self.alert.setText(_translate("Dialog", "报警项目"))




class Show_Text(QDialog, Ui_Dialog):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.some_room = ""
        self.some_machine = "" 
        self.some_project = ""
        print(self.some_room)
        print(self.some_machine)
        print(self.some_project)
        self.setupUi(self)
        self.show_text_thread = showtext_Thread(self.some_room,self.some_machine,self.some_project)
        self.show_text_thread.start()


    @pyqtSlot(str, str, str)
    def show_Data(self, room, machine, project):#数据更新    
        self.textBrowser.append(room)   
        self.textBrowser_2.append(machine)
        self.textBrowser_3.append(project)  

class showtext_Thread(QtCore.QThread):
    trigger = QtCore.pyqtSignal(str,str,str)

    def __init__(self, room, machine, project, parent=None):
        super(showtext_Thread, self).__init__(parent)
        self.thread_room = room
        self.thread_machine = machine
        self.thread_project = project


    def run(self):


        print(self.thread_room)
        self.trigger.emit(self.thread_room,self.thread_machine,self.thread_project) 

        time.sleep(1)

    def stop(self):
        self.quit()
        self.wait()
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

相关推荐