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

Abigail ·
更新时间:2024-09-20
· 842 次阅读

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

#!/usr/bin/python3 # -*- coding: utf-8 -*- """ PyQt5 教程 在这个例子中,我们显示窗口上的图像。 作者:我的世界你曾经来过 博客:http://blog.csdn.net/weiaitaowang 最后编辑:2016年8月4日 """ import sys from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QLabel from PyQt5.QtGui import QPixmap class 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 控件。

程序执行后

您可能感兴趣的文章:PyQt5打开文件对话框QFileDialog实例代码Python PyQt5标准对话框用法示例PyQt5每天必学之事件与信号PyQt5每天必学之切换按钮PyQt5每天必学之滑块控件QSliderPyQt5每天必学之组合框PyQt5每天必学之拖放事件PyQt5每天必学之单行文本框PyQt5每天必学之日历控件QCalendarWidgetpython3+PyQt5+Qt Designer实现扩展对话框



像素图 pyqt5 pyqt 像素

需要 登录 后方可回复, 如果你还没有账号请 注册新账号