当前位置:网站首页>python开发qt程序读取图片的简单流程
python开发qt程序读取图片的简单流程
2020-11-08 16:17:00 【spiritboy】
python开发qt程序的简单流程
一. python 安装pyqt5
pip install pyqt5 -i https://mirrors.aliyun.com/pypi/simple
二. 安装qt designer(设计生成程序界面ui)
下载地址
(官方)https://build-system.fman.io/qt-designer-download
(csdn)https://download.csdn.net/download/qq_26696715/13094628
(加群下载)686070107
三. 使用qt designer设计生成ui文件
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>635</width>
<height>511</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>81</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>选择图片</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>581</width>
<height>401</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>img/1.tif</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
四. 将ui文件转换成py文件
pyuic5 -o ui.py ui.ui
五. 编写main.py文件调用ui.py文件
# -*- coding: utf-8 -*-
import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import numpy as np
import cv2
import qimage2ndarray
from ui import Ui_Dialog
class mwindow(QWidget, Ui_Dialog):
def __init__(self):
super(mwindow, self).__init__()
self.setupUi(self)
#选择图片
def openimage(self):
#选择图片
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "img", "*.jpg;*.tif;*.png;;All Files(*)")
if imgName=="":
return 0
#qt5读取图片
jpg = QPixmap(imgName).scaled(self.label.width(), self.label.height())
#显示原图
self.label.setPixmap(jpg)
if __name__ == '__main__':
app=QApplication(sys.argv)
#初始化窗口
m=mwindow()
#绑定按钮事件
m.pushButton.clicked.connect(m.openimage)#选择图片
m.show()
sys.exit(app.exec_())
六. 运行main.py文件
python main.py
有问题添加QQ群:686070107
版权声明
本文为[spiritboy]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/3337401/blog/4708233
边栏推荐
- Huawei has an absolute advantage in the 5g mobile phone market, and the market share of Xiaomi is divided by the market survey organization
- Tips and skills of CSP examination
- Gopherchina 2020 Conference
- C + + things: from rice cookers to rockets, C + + is everywhere
- What is the database paradigm
- [开源] .Net 使用 ORM 访问 华为GaussDB数据库
- 浅谈OpenGL之DSA
- I used Python to find out all the people who deleted my wechat and deleted them automatically
- How does the system response time and throughput change with the increase of concurrency pressure during performance pressure testing
- 模板引擎的整理归纳
猜你喜欢
京东落地DevOps平台时爆发的冲突如何解决?
第五章编程题
Flink from introduction to Zhenxiang (10. Sink data output elasticsearch)
华为在5G手机市场占据绝对优势,市调机构对小米的市占出现分歧
How to solve the difference between NAT IP and port IP
VIM configuration tutorial + source code
Talking about, check the history of which famous computer viruses, 80% of the people do not know!
Builder pattern
Flink: from introduction to Zhenxiang (3. Reading data from collection and file)
Recurrence of Apache kylin Remote Code Execution Vulnerability (cve-2020-1956)
随机推荐
Flink from introduction to Zhenxiang (7. Sink data output file)
第五章编程题
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
What is SVG?
浅谈,盘点历史上有哪些著名的电脑病毒,80%的人都不知道!
What is the database paradigm
svg究竟是什么?
谷歌开源能翻译101种语言的AI模型,只比Facebook多一种
Drink soda, a bottle of soda water 1 yuan, two empty bottles can change a bottle of soda, give 20 yuan, how much soda can you
How to cooperate with people in software development? |Daily anecdotes
2035 we will build such a country
How to make a correct summary for 7 years?
Golang 系统ping程序探测存活主机(任意权限)
Workers, workers soul, draw lifelong members, become a person!
聊聊Go代码覆盖率技术与最佳实践
Interpretation of deepmind's latest paper: the causal reasoning algorithm in discrete probability tree is proposed for the first time
C + + things: from rice cookers to rockets, C + + is everywhere
wanxin finance
腾讯:阿里的大中台虽好,但也不是万能的!
数据库连接报错之IO异常(The Network Adapter could not establish the connection)