zoukankan      html  css  js  c++  java
  • <pyqt5>显示图片

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

      

  • 相关阅读:
    CSS3 Transitions 你可能不知道的知识点
    css规范
    移动应用表单设计秘籍
    SVN和Git的一些用法总结
    让Terminal显示git分支
    JavaScript正则表达式下——相关方法
    requests模块
    flask模块
    os模块
    简单的socket编程
  • 原文地址:https://www.cnblogs.com/shuimohei/p/13673549.html
Copyright © 2011-2022 走看看