顯示圖片


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_())

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM