pyqt5使用label显示图片

关于label的介绍很详细的地址:https://zhuanlan.zhihu.com/p/32134728

代码如下

import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication, QLabel
from PyQt5.QtGui import QPalette, QBrush, QPixmap

 
 
class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI() #界面绘制交给InitUi方法
        
    def initUI(self):
        
        pix = QPixmap('background.jpg')

        lb1 = QLabel(self)
        lb1.setGeometry(0,0,300,200)
        lb1.setStyleSheet("border: 2px solid red")
        lb1.setPixmap(pix)

        
        #设置窗口的位置和大小
        self.setGeometry(300, 300, 600, 600)  
        #设置窗口的标题
        self.setWindowTitle('Example')
        
        
        #显示窗口
        self.show()
        
        
if __name__ == '__main__':
    #创建应用程序和对象
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_()) 

猜你喜欢

转载自blog.csdn.net/pursuit_zhangyu/article/details/82918605
今日推荐