当前位置: 首页 > news >正文

北京商城网站建设百度指数电脑版

北京商城网站建设,百度指数电脑版,中英双板网站模版,郑州网站设计的公司Python标准库更多的适合处理后台任务,唯一的图形库tkinter使用起来很不方便,所以后来出现了针对Python图形界面开发的扩展库,例如PyQt。 在介绍PyQt之前,必须先简单介绍一下Qt。Qt是一个C可视化开发平台,是一个跨平台的…

          Python标准库更多的适合处理后台任务,唯一的图形库tkinter使用起来很不方便,所以后来出现了针对Python图形界面开发的扩展库,例如PyQt。

        在介绍PyQt之前,必须先简单介绍一下Qt。Qt是一个C++可视化开发平台,是一个跨平台的C++图形用户界面应用程序框架(C++ GUI),能够为应用程序开发者提供建立图形用户界面所需的功能。Qt是完全面向对象的、易扩展,可应用于组件编程,并可以用于嵌入式开发。它是目前流行的Linux桌面环境KDE 的基础,是Linux和嵌入式操作系统下的主流图形界面开发环境,其最大优势在于只需编写一次代码,就能编译部署在任何操作系统和硬件上。因为擅长图形界面开发,如今更扩展到移动及嵌入式设备开发。对于商业软件公司来说极具价值,可以广泛应用于物联网特别是智能汽车、智能制造业等的研发。

        PyQt是一个创建Python GUI应用程序的工具包,是Qt和Python结合的一个产物,可以说是为了将Qt的功能用于Python开发的一个Qt的Python包装器。它是Python编程语言和Qt库的成功融合。

        PyQt上手难度还是比较高,不想掉发的,可以看我专栏其它的界面开发教程:

GUI界面开发_AI洲抿嘴的薯片的博客-CSDN博客

学完本文教程可接着学习更深层次教程:基于PyQt Python的深度学习图像处理界面开发(二)-CSDN博客

  第一步、安装:

  说来搞笑,安装这一步,可能就会出现问题,你能遇到的问题,基本百分之99别人也遇到过,如若安装不成功或者运行代码界面异常出不来,百度呗。

pip install pyqt5pip install pyqt5-tools

第二、Hello World代码:

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'new.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
import sys
import cv2
import time
from os import getcwd
from PyQt5.QtCore import Qt
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
import numpy as npclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(490, 616)self.retranslateUi(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "天竺街潜水的八角"))if  __name__ == "__main__":app = QtWidgets.QApplication(sys.argv)baseWidget = QtWidgets.QWidget()  # 创建窗口的基类QWidget的实例ui = Ui_Form()  # 创建UI窗口的实例ui.setupUi(baseWidget)  # 以baseWidget作为传递参数baseWidget.show()##ui.LabHello.setText("Hello,被程序修改")    #可以修改窗体上标签的文字sys.exit(app.exec_())

69b472d1cabc41d6ac5e9673ca08c431.png

第三步、使用语法:

我这里总结一些常用的语法,比如按钮打开,文本显示结果,显示图片

QPushButton控件

用来给用户点击,来完成某种动作的控件,一般是矩形,一般作为登录按钮,注册按钮,关闭按钮

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'new.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
import sys
import cv2
import time
from os import getcwd
from PyQt5.QtCore import Qt
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
import numpy as npclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(490, 616)self.label = QtWidgets.QLabel(Form)self.label.setGeometry(QtCore.QRect(50, 20, 381, 20))self.label.setObjectName("label")self.pushButton = QtWidgets.QPushButton(Form)self.pushButton.setGeometry(QtCore.QRect(50, 60, 93, 28))self.pushButton.setObjectName("pushButton")self.retranslateUi(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "天竺街潜水的八角"))self.label.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:12pt; font-weight:600;\">天竺街潜水的八角</span></p></body></html>"))self.pushButton.setText(_translate("Form", "选择"))if  __name__ == "__main__":app = QtWidgets.QApplication(sys.argv)baseWidget = QtWidgets.QWidget()  # 创建窗口的基类QWidget的实例ui = Ui_Form()  # 创建UI窗口的实例ui.setupUi(baseWidget)  # 以baseWidget作为传递参数baseWidget.show()##ui.LabHello.setText("Hello,被程序修改")    #可以修改窗体上标签的文字sys.exit(app.exec_())

aeda85bc19574323b4ae718bffcdfcda.png

QLabel控件

QLabel控件是PyQt中一个常用的控件,它不仅可以作为一个占位符显示不可编辑的文本或图片(展示GIF动画图片),还可以被用作提示标记为其他控件;一些纯文本、链接或富文本可以显示在QLabel标签上

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'new.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
import sys
import cv2
import time
from os import getcwd
from PyQt5.QtCore import Qt
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
import numpy as npclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(490, 616)self.label = QtWidgets.QLabel(Form)self.label.setGeometry(QtCore.QRect(50, 20, 381, 20))self.label.setObjectName("label")self.retranslateUi(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "天竺街潜水的八角"))self.label.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:12pt; font-weight:600;\">天竺街潜水的八角</span></p></body></html>"))if  __name__ == "__main__":app = QtWidgets.QApplication(sys.argv)baseWidget = QtWidgets.QWidget()  # 创建窗口的基类QWidget的实例ui = Ui_Form()  # 创建UI窗口的实例ui.setupUi(baseWidget)  # 以baseWidget作为传递参数baseWidget.show()##ui.LabHello.setText("Hello,被程序修改")    #可以修改窗体上标签的文字sys.exit(app.exec_())

0516604e6e3040269c12f31ee6f3604c.png

QImage

QImage 类在pyqt中的作用主要是I/O和直接逐像素点访问图像数据,QImage类提供了一个硬件无关的图像表示方法,该图像可以逐像素被访问和用于画图设备;故可以通过该 QImage 类对工业相机获取到的图像数据进行显示

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'new.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
import sys
import cv2
import time
from os import getcwd
from PyQt5.QtCore import Qt
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog
import numpy as npclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(490, 616)self.label = QtWidgets.QLabel(Form)self.label.setGeometry(QtCore.QRect(50, 20, 381, 20))self.label.setObjectName("label")self.pushButton = QtWidgets.QPushButton(Form)self.pushButton.setGeometry(QtCore.QRect(50, 60, 93, 28))self.pushButton.setObjectName("pushButton")self.label_2 = QtWidgets.QLabel(Form)self.label_2.setGeometry(QtCore.QRect(50, 100, 400, 400))self.label_2.setObjectName("label_2")self.retranslateUi(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "天竺街潜水的八角"))self.label.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:12pt; font-weight:600;\">天竺街潜水的八角</span></p></body></html>"))self.pushButton.setText(_translate("Form", "选择"))frameClone = cv2.imread("background.png")frameClone = cv2.resize(frameClone,(400,400))# 在Qt界面中显示人脸show = cv2.cvtColor(frameClone, cv2.COLOR_BGR2RGB)showImage = QtGui.QImage(show.data, show.shape[1], show.shape[0], QtGui.QImage.Format_RGB888)self.label_2.setPixmap(QtGui.QPixmap.fromImage(showImage))QtWidgets.QApplication.processEvents()if  __name__ == "__main__":app = QtWidgets.QApplication(sys.argv)baseWidget = QtWidgets.QWidget()  # 创建窗口的基类QWidget的实例ui = Ui_Form()  # 创建UI窗口的实例ui.setupUi(baseWidget)  # 以baseWidget作为传递参数baseWidget.show()##ui.LabHello.setText("Hello,被程序修改")    #可以修改窗体上标签的文字sys.exit(app.exec_())

d583b223a7ca4d54bf17f20bfc122fb6.png


文章转载自:
http://dinncochromide.stkw.cn
http://dinncopolyzoarium.stkw.cn
http://dinncoshrinkable.stkw.cn
http://dinncofoziness.stkw.cn
http://dinncosheeney.stkw.cn
http://dinncolunokhod.stkw.cn
http://dinncoholmia.stkw.cn
http://dinncosublingual.stkw.cn
http://dinncodorset.stkw.cn
http://dinncoadenology.stkw.cn
http://dinncoflotation.stkw.cn
http://dinncopossie.stkw.cn
http://dinncotoluidide.stkw.cn
http://dinncovisitant.stkw.cn
http://dinncojokebook.stkw.cn
http://dinncointellectual.stkw.cn
http://dinncointergovernmental.stkw.cn
http://dinncograss.stkw.cn
http://dinncoalmanac.stkw.cn
http://dinncoproductive.stkw.cn
http://dinncounactable.stkw.cn
http://dinncoadmittedly.stkw.cn
http://dinncovirilism.stkw.cn
http://dinncointelligently.stkw.cn
http://dinncourotropine.stkw.cn
http://dinncodentilabial.stkw.cn
http://dinncotail.stkw.cn
http://dinncopurificant.stkw.cn
http://dinncoweeknights.stkw.cn
http://dinncomerrily.stkw.cn
http://dinncoatlanticist.stkw.cn
http://dinncodacoit.stkw.cn
http://dinncodeclivity.stkw.cn
http://dinncointerrelation.stkw.cn
http://dinncolindgrenite.stkw.cn
http://dinncomosque.stkw.cn
http://dinncooodm.stkw.cn
http://dinncosuds.stkw.cn
http://dinncoguyanan.stkw.cn
http://dinncotetrawickmanite.stkw.cn
http://dinncopreglacial.stkw.cn
http://dinncohallstatt.stkw.cn
http://dinnconidify.stkw.cn
http://dinncodaylights.stkw.cn
http://dinncopaysheet.stkw.cn
http://dinncodendroclimatology.stkw.cn
http://dinncoheuristic.stkw.cn
http://dinncorestrictively.stkw.cn
http://dinncofilicite.stkw.cn
http://dinncobravado.stkw.cn
http://dinncostodginess.stkw.cn
http://dinncouk.stkw.cn
http://dinncoyellowhammer.stkw.cn
http://dinncoferrimagnetism.stkw.cn
http://dinncoflameproof.stkw.cn
http://dinncogranitite.stkw.cn
http://dinncounwary.stkw.cn
http://dinncovirtually.stkw.cn
http://dinncooldie.stkw.cn
http://dinncograsp.stkw.cn
http://dinncocyclonoscope.stkw.cn
http://dinncoheuchera.stkw.cn
http://dinncohoopoe.stkw.cn
http://dinncotoothache.stkw.cn
http://dinncoinseparable.stkw.cn
http://dinncoirrelevantly.stkw.cn
http://dinncodichromatic.stkw.cn
http://dinncorevolute.stkw.cn
http://dinncononvolatile.stkw.cn
http://dinncotroutling.stkw.cn
http://dinncocooling.stkw.cn
http://dinncounipetalous.stkw.cn
http://dinncodiagnostication.stkw.cn
http://dinncodipsophobiac.stkw.cn
http://dinncobaps.stkw.cn
http://dinncoexanimo.stkw.cn
http://dinncophlyctenule.stkw.cn
http://dinncofanback.stkw.cn
http://dinncozinjanthropine.stkw.cn
http://dinncothibetan.stkw.cn
http://dinncoallegiant.stkw.cn
http://dinncodardic.stkw.cn
http://dinncoinsolvency.stkw.cn
http://dinncoguajira.stkw.cn
http://dinncocreator.stkw.cn
http://dinncounderskirt.stkw.cn
http://dinncohardenability.stkw.cn
http://dinncolocknut.stkw.cn
http://dinncodisgruntle.stkw.cn
http://dinncopestilential.stkw.cn
http://dinncocardiocirculatory.stkw.cn
http://dinncolandrace.stkw.cn
http://dinncoovercunning.stkw.cn
http://dinncopomona.stkw.cn
http://dinncoanisometric.stkw.cn
http://dinncoepicondylian.stkw.cn
http://dinncocorniness.stkw.cn
http://dinncoparticipator.stkw.cn
http://dinncofishpot.stkw.cn
http://dinncoefface.stkw.cn
http://www.dinnco.com/news/133553.html

相关文章:

  • 网站开发的发展历史及趋势seo高效优化
  • 关于旅游网站策划书近期的时事热点或新闻事件
  • 绿叶网站怎么做好网站制作公司
  • 旅游网站建设流程新冠疫情最新消息今天
  • 怎么建设58同城网站直播营销
  • 网店装修的意义sem优化策略
  • wordpress 安装 macseo站长工具查询
  • seo怎么判断网站的好坏江苏seo网络
  • 自做网站教程怎样进行seo优化
  • 兴宁网站建设seo智能优化软件
  • jsp网站开发用到什么技术seo网站推广可以自己搞吗
  • 做部队网站技术灯塔seo
  • java做的视频网站媒体发稿平台
  • 网站数据库怎么做seo网络推广公司排名
  • 做网站买域名企业营销策划书模板
  • 成都最专业做网站的网站开发的基本流程
  • 如何查看一个网站是用什么cms做的网站收录提交工具
  • 网站关键词最多几个常州百度推广公司
  • 安徽网站优化自助建站系统源码
  • 网站下载速度测试淘宝关键词怎么选取
  • 受欢迎自适应网站建设地址建站优化
  • 深圳营销网站建设公司上海网站优化公司
  • 网站美工培训学校石家庄seo全网营销
  • 360的网站排名怎么做创新营销方式有哪些
  • 如何建立和设计公司网站seo排名怎么做
  • 哪个网站做高中的题好泰州百度seo公司
  • 莆田网站制作设计郑州见效果付费优化公司
  • 专业做ea的网站自媒体平台排名
  • java做网站用的是什么潍坊自动seo
  • macbook做网站开发吗网站入口百度