pyqt5将图片插入面板

pyqt5将图片插入面板

 from PyQt5.QtWidgets import *
from PyQt5 import QtCore,QtWidgets
from PyQt5.QtGui import * import sys
class A(QWidget):
def __init__(self):
super(A,self).__init__()
self.setFixedSize(400,500)
self.layout=QGridLayout(self)
self.btn=QPushButton('添加')
self.layout.addWidget(self.btn)
self.setLayout(self.layout)
self.btn.clicked.connect(self.btn1)
def btn1(self):
label={}
ok,f=QFileDialog.getOpenFileNames(self,'打开','/','jpg(*.jpg)')
for i,j in enumerate(ok):
label[i]=QLabel(str(i))
label[i].setFixedSize(500,500)
self.layout.addWidget(label[i])
pix=QPixmap(j)
label[i].setPixmap(pix)
self.resize(pix.width(),pix.height())
if __name__ == '__main__':
app = QApplication(sys.argv)
a = A()
a.show()
sys.exit(app.exec_())

pyqt5将图片插入面板

上一篇:Python 解LeetCode:671. Second Minimum Node In a Binary Tree


下一篇:解决图片元素下多余空白的BUG