当前位置:网站首页>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
边栏推荐
- Recurrence of Apache kylin Remote Code Execution Vulnerability (cve-2020-1956)
- How to solve the difference between NAT IP and port IP
- 京东落地DevOps平台时爆发的冲突如何解决?
- 模板引擎的整理归纳
- On DSA of OpenGL
- “他,程序猿,35岁,被劝退”:不要只懂代码,会说话,胜过10倍默默努力
- svg究竟是什么?
- AI weekly: employees are allowed to voluntarily reduce salary; company response: employees are happy and satisfied; tiger tooth HR takes employees out of the company; Sweden forbids Huawei ZTE 5g equi
- 使用K3S创建本地开发集群
- 我用 Python 找出了删除我微信的所有人并将他们自动化删除了
猜你喜欢
How to cooperate with people in software development? |Daily anecdotes
2035 we will build such a country
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
基于阿里云日志服务快速打造简版业务监控看板
I used Python to find out all the people who deleted my wechat and deleted them automatically
阿里云加速增长,进一步巩固领先优势
Flink的sink实战之一:初探
Alibaba cloud accelerates its growth and further consolidates its leading edge
重返全球第三,小米做对了什么?
DeepMind 最新论文解读:首次提出离散概率树中的因果推理算法
随机推荐
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
二叉树的四种遍历方应用
Alibaba cloud accelerates its growth and further consolidates its leading edge
Station B STM32 video learning
金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0
关于update操作并发问题
[Python 1-6] Python tutorial 1 -- number
Design by contract (DBC) and its application in C language
Golang 系统ping程序探测存活主机(任意权限)
Xiaoqingtai officially set foot on the third day of no return
构建者模式(Builder pattern)
laravel8更新之维护模式改进
On the concurrency of update operation
What are the necessary laws and regulations to know when entering the Internet?
区块链周报:数字货币发展写入十四五规划;拜登邀请MIT数字货币计划高级顾问加入总统过渡团队;委内瑞拉推出国营加密交易所
It's just right. It's the ideal state
契约式设计(Dbc)以及其在C语言中的应用
聊聊Go代码覆盖率技术与最佳实践
markdown使用
svg究竟是什么?