网络编程
位置:首页>> 网络编程>> Python编程>> PyQt5每天必学之像素图控件QPixmap

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

作者:我的世界你曾经来过  发布时间:2022-04-05 04:42:54 

标签: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

来源:https://blog.csdn.net/weiaitaowang/article/details/52118928

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com