import sys
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *


class picture(QWidget):
    def __init__(self):
        super(picture, self).__init__()

        self.resize(800, 600)
        self.setWindowTitle("label显示图片")

        self.label = QLabel(self)
        self.label.setText("显示图片")
        self.label.setFixedSize(600, 400)
        self.label.move(160, 160)

        self.label.setStyleSheet("QLabel{background:white;}"
                                 "QLabel{color:rgb(300,300,300,120);font-size:10px;font-weight:bold;font-family:宋体;}"
                                 )

        btn = QPushButton(self)
        btn.setText("打开图片")
        btn.move(10, 30)
        btn.clicked.connect(self.openimage)

    def openimage(self):
        imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "*.jpg;;*.png;;All Files(*)")
        jpg = QtGui.QPixmap(imgName).scaled(self.label.width(), self.label.height())
        self.label.setPixmap(jpg)


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    my = picture()
    my.show()
    sys.exit(app.exec_())

  

相关文章:

  • 2021-11-09
  • 2021-10-22
  • 2021-06-11
  • 2021-07-11
  • 2021-08-10
  • 2021-12-08
  • 2021-08-30
  • 2022-01-20
猜你喜欢
  • 2022-12-23
  • 2021-04-24
  • 2021-06-06
  • 2021-08-03
  • 2021-11-07
  • 2022-01-01
  • 2021-11-21
相关资源
相似解决方案