首页 > 编程 > Python > 正文

PyQt5每天必学之像素图控件QPixmap

2019-11-25 14:54:02
字体:
来源:转载
供稿:网友

QPixmap 像素图控件是用来处理图像的控件之一。它用于将优化后的图像显示在屏幕上。在我们的代码示例中,我们将使用QPixmap 控件在程序窗口上显示图像。

#!/usr/bin/python3# -*- coding: utf-8 -*-"""PyQt5 教程在这个例子中,我们显示窗口上的图像。作者:我的世界你曾经来过博客:http://blog.csdn.net/weiaitaowang最后编辑:2016年8月4日"""import sysfrom PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QLabelfrom PyQt5.QtGui import QPixmapclass Example(QWidget):  def __init__(self):    super().__init__()    self.initUI()  def initUI(self):    hbox = QHBoxLayout(self)    pixmap = QPixmap('F:/Python/PyQt5/Widgets/images/liutao.png')    lb1 = QLabel(self)    lb1.setPixmap(pixmap)    hbox.addWidget(lb1)    self.setLayout(hbox)    self.move(300, 300)    self.setWindowTitle('像素图控件')        self.show()  def showDate(self, date):    self.lb1.setText(date.toString())if __name__ == '__main__':  app = QApplication(sys.argv)  ex = Example()  sys.exit(app.exec_())

在我们的例子中,我们将图像显示在该程序的窗口上。

pixmap = QPixmap('F:/Python/PyQt5/Widgets/images/liutao.png')

我们创建的QPixmap 对象需要一个文件作为参数。

lb1 = QLabel(self)lb1.setPixmap(pixmap)

我们把QPixmap 对象映射到的QLabel 控件。

程序执行后

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表