PyQt5每天必学之像素图控件QPixmap
2019/7/15 0:54:15
本文主要是介绍PyQt5每天必学之像素图控件QPixmap,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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每天必学之像素图控件QPixmap的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python