问题描述
我在PyCharm中使用PyQt5创建了一个gui,并且设法显示了其中一个带有图像(Picture1.png)的QLabel,但是,当我尝试添加带有第二个图像的第二个QLabel(在同一个窗口上名为Shutter1.png的文件),似乎同时删除了两个标签,并且GUI上没有任何显示。我不确定我要去哪里出错,对您的任何帮助将不胜感激,我是新手!注意:我已经仔细检查了imagePath和imagePath_1的文件路径是否正确。参见下面的附加代码:
from PyQt5 import uic,QtWidgets,QtGui,QtCore
import sys
import pkg_resources
import functions.initialisation as inits
import functions.Sig2Open as S2O
import functions.Sig2Close as S2C
class Ui(QtWidgets.QMainWindow):
def __init__(self):
super(Ui,self).__init__()
self.gui = uic.loadUi('Shuttergui.ui',self)
# Creates the path of the image
self.imagePath = "C:/........../Picture1.png"
self.label = QtWidgets.QLabel(self.gui)
self.image = QtGui.QImage(self.imagePath)
self.pixmapImage = QtGui.QPixmap.fromImage(self.image)
self.label.setPixmap(self.pixmapImage)
self.label.resize(self.width(),self.height())
self.label.move(60,170)
self.imagePath = "C:/....../Shutter1.png"
# Create label that holds the image in imagePath
self.label_1 = QtWidgets.QLabel(self.gui)
self.image_1 = QtGui.QImage(self.imagePath)
self.pixmapImage_1 = QtGui.QPixmap.fromImage(self.image_1)
self.label_1.setPixmap(self.pixmapImage_1)
self.label_1.resize(self.width(),self.height())
self.label_1.move(60,170)
self.gui.showMaximized()
# redirect closeevent func to main self rather than inside gui
self.gui.closeEvent = self.closeEvent
# Initialise shutter functions
inits.ardopenup(self)
inits.ardshutup(self)
self.gui.show()
def closeEvent(self,event):
import time
time.sleep(0.1)
print("main thread quitting")
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
app.setStyleSheet(pkg_resources.resource_stream(__name__,'/css/darktheme/style.css').read().decode())
window = Ui()
sys.exit(app.exec_())
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)