脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - PyQt5每天必学之像素图控件QPixmap

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

2021-02-02 00:33我的世界你曾经来过 Python

这篇文章主要为大家详细介绍了PyQt5每天必学之像素图控件QPixmap,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/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_())

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

?
1
pixmap = QPixmap('F:\Python\PyQt5\Widgets\images\liutao.png')

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

?
1
2
lb1 = QLabel(self)
lb1.setPixmap(pixmap)

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

程序执行后

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

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

原文链接:https://blog.csdn.net/weiaitaowang/article/details/52118928

延伸 · 阅读

精彩推荐