将PyQt5 GUI与其他python程序集成
我已经用PyQt5构建了一个GUI,现在我想将它与另一个python程序集成。我以前是通过将用TKinter编写的GUI代码放在一个单独的线程中来实现这一点的。我想知道如何以最佳方式将这个PyQt GUI集成到我的其他代码中 我的另一个程序有两个线程监控旋转编码器,主线程在RFID阅读器上工作+一些数据库通信 PyQt GUI必须是程序的主线程吗 以下是PyQt gui:将PyQt5 GUI与其他python程序集成,python,multithreading,qt,user-interface,pyqt,Python,Multithreading,Qt,User Interface,Pyqt,我已经用PyQt5构建了一个GUI,现在我想将它与另一个python程序集成。我以前是通过将用TKinter编写的GUI代码放在一个单独的线程中来实现这一点的。我想知道如何以最佳方式将这个PyQt GUI集成到我的其他代码中 我的另一个程序有两个线程监控旋转编码器,主线程在RFID阅读器上工作+一些数据库通信 PyQt GUI必须是程序的主线程吗 以下是PyQt gui: from PyQt5 import QtGui from PyQt5.QtWidgets import QApplicati
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QTableWidget, QTableWidgetItem, QVBoxLayout, QLabel
from PyQt5.QtGui import QPixmap
import sys
class Reminder():
def __init__(self):
self.activity = 'activity' # instance variable unique to each instance
self.time = 0000
self.day = 'day'
self.multiple_days = False
class Window(QWidget):
def __init__(self):
super().__init__()
self.titel = "GUI for Andreas"
self.top = 150
self.left = 150
self.width = 500
self.height = 500
self.setWindowIcon(QtGui.QIcon("calender.png"))
self.InitWindow()
def InitWindow(self):
self.setWindowTitle(self.titel)
self.setGeometry(self.top,self.left,self.width,self.height)
self.creatingTables(test_list)
self.vBoxLayout = QVBoxLayout()
self.vBoxLayout.addWidget(self.tableWidget)
self.setLayout(self.vBoxLayout)
self.textWidgets()
self.vBoxLayout.addWidget(self.timelabel)
self.vBoxLayout.addWidget(self.daylabel)
self.show()
def creatingTables(self, planned_activities):
self.tableWidget = QTableWidget()
self.tableWidget.setRowCount(len(planned_activities))
self.tableWidget.setColumnCount(4)
count = 0
for i in planned_activities:
index = 0 + count
self.label = QLabel(self)
self.label.setPixmap(QPixmap('%s.png' %i.activity))
self.tableWidget.setCellWidget(index,0, self.label)
self.tableWidget.setItem(index,1, QTableWidgetItem(i.activity))
self.tableWidget.setItem(index,2, QTableWidgetItem(i.day))
self.tableWidget.setItem(index,3, QTableWidgetItem(str(i.time)))
count +=1
def textWidgets(self):
self.timelabel = QLabel(self)
self.daylabel = QLabel(self)
self.timelabel.setText("Time:%s" %glo_dict['Time'])
self.daylabel.setText("Day:%s" %glo_dict['Day'])
glo_dict = {'Time': 0000, 'Day': 'None'} #This dict will be updated by other threads in main code
#Simple test object, these objects will be made by the main thread in the other program.
test_list=[]
a = Reminder()
a.time = 1123
a.day = 'Monday'
a.activity = 'rolling'
test_list.append(a)
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())
PyQt和Tkinter不能共存。您的事件循环将是blocked@eyllanesc我没有运行任何Tkinter代码,我试图描述我以前使用Tkinter所做的工作PyQt GUI对程序的主线程有什么影响?是的,Qt要求这是在主线程中,您的问题是什么?@eyllanesc谢谢!我希望不会,因为我的其他程序的主线程中运行了其他东西。我现在必须重写它,以便PyQTGUI可以成为那里的主线程。