2 Star 6 Fork 3

IIS_Chaer / Pyqt5-Interface-Function

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

Pyqt5

综述:利用python的pyqt库实现一个简洁的pyqt5界面,代码在本地测试通过,其中功能实现部分代码写的粗糙,仅为了实现功能,所以可扩展性较差,可能需要反复阅读源码才可以了解不同功能间的衔接关系,如有问题可以和我联系

因为项目中所用到的图片数据并不开放,所以只提供部分数据保证能正常运行 在image_out中给出了车辆右侧下的图片,考虑到下载可能缓慢,给出baidu云链接,这个数据集好像也不公开,还是算了吧,想要的可以私聊我 前期图像处理:高铁车身采集图像(分为很多个部分,如右上,右下,车底中等),对图象进行目标识别和分类,绘制对应目标框,对每个目标进行缺陷识别。 软件功能:导入已有的检测结果文件,对图片进行显示,对缺陷结果进行二次确认,并写入本地文档保存。在Demonstration.rar中是整个软件的演示视频。

上手指南

以下指南将帮助你在本地机器上安装和运行该项目,进行开发和测试。

运行要求

以下环境为必须项

  • python 3 环境
  • 安装必要的依赖PyQt 5包,注意PyQt 4 和PyQt 5有许多差异,本项目基于PyQt 5环境,无法在4环境中正常运行
  • 安装其他python库 安装步骤不做赘述,自行搜索解决

界面介绍

界面中主要控件通过安装PyQt 之后自带的软件拖动生成,安装完成之后在你的python环境下的scripts中有直接运行的.exe软件。

关于软件的使用请自行解决,最好实际设计一个界面,然后花时间去探索各个控件的实际作用和使用方法。

软件主体为两个界面,login界面和function界面,其中的美化及详细的界面跳转和功能实现在之后详细介绍。

登录界面

功能界面

实现步骤

  1. 代码生成

这里我使用的是vscode进行代码编写,配置完成相关环境之后,可以直接右键相关.ui文件,就可以直接转化为python代码 直接生成python代码 也可以使用命令行指令:

pyuic5 -o ui_window.ui py_window.py

(没有测试过,来源于CSDN) 利用此方法生成的py文件如果我们重新修改界面后再次生成时,其中自己编写的功能函数都不会被保存,这在其生成代码中也给出了相应警告

WARNING! All changes made in this file will be lost!

所以在这里,我们通过再再新建一个py文件方式解决这个问题,因为使用QtDesigner程序(即安装pyqt之后自带的图形化软件)只是对界面进行简单的初步生成,所以我们可以新建一个my_Window的类,继承来自ui文件生成的类。这样,我们一切的修改都在子类中进行,最后也直接运行子类,从而保证自己修改和添加的功能不会遗失。

  1. 实例化代码介绍

    首先我们对类和函数及衔接进行简单介绍:

  • PyQt5是一个大的模块,是Qt在Python中的桥梁。
  • QtWidgets是PyQt5下面的一个模块,包含了用于构建界面的一系列UI元素组件。
  • QApplication是QtWidgets模块下面的一个类。

QApplication用法

app = QApplication(sys.argv)   # 实例化一个应用对象
w = QWidget()   # 窗口界面的基本控件,它提供了基本的应用构造器。默认情况下,构造器是没有父级的,没有父级的构造器被称为窗口(window)。
w.show()   # 让控件在桌面上显示出来。控件在内存里创建,之后才能在显示器上显示出来。
sys.exit(app.exec_())   # 确保主循环安全退出

任何一个窗体建设中都会有这么类似的4句。 sys.argv是一组命令行参数的列表。Python可以在shell里运行,这个参数提供对脚本控制的功能。 PyQT5.QtWidgets.QApplication结构及用法

  1. 登录界面及功能
  • 界面

    登录界面比较简单,因为背景比较复杂,不具有模块性,所以通过直接插入一张背景图的方式解决。在qt中画图的方式有多种,在这里使用paintEvent函数,它是QWidget类中的虚函数,用于ui的绘制,会在多种情况下被其他函数自动调用。 当然还有其他很多绘制方式,请自行实践解决(QPixmap/QImage/QPicture)

def paintEvent(self, event):
    painter = QPainter(self)
    pixmap = QPixmap("./software_images/background.png")
    painter.drawPixmap(self.rect(), pixmap)
  • 功能

    登录是通过 QPushButton 控件实现的,这里不要求对密码进行自动填充(1),也不进行后台数据库判断(2),只是简单的进行本地程序检查。以上所描述功能(1)(2)都可以实现,需要的可自行百度解决。

# 将点击事件与槽函数进行连接
    self.button_login.clicked.connect(self.login_func)
    self.button_login.setShortcut(QtCore.Qt.Key_Return)
    self.account = "admin"
    self.password = "test123"
...
# 省略

    # 登录按钮,函数
def login_func(self):
    # 获取用户的输入账号和密码
    account = self.input_account.text()
    password = self.input_pas.text()
    if account == "" or password == "":
        reply = QMessageBox.warning(self,"警告","账号或者密码不能为空!")
        return 
        # 因为本软件不需要进行数据库连接 所以进行默认设置
    if account== self.account and  password == self.password:
        func_window.show()
        self.close()
    else:
        reply = QMessageBox.warning(self,"警告","账号或者密码输入错误!")
  • 窗口切换

利用QWidget类中的show()函数,可以实现窗口的显示,在正确判定之后,关闭当前login窗口,同时显示function窗口,这里所用到的move()函数设置窗口的左上角坐标,为了让窗口在屏幕上显示位置恒定居中一点。

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = Login_window() #生成一个实例
    func_window = Func_window()
    func_window.move((app.desktop().width() - func_window.width()) / 2, (app.desktop().height() - func_window.height()) / 4)
    window.move((app.desktop().width() - window.width()) / 2 , (app.desktop().height() - window.height()) / 2 )
    window.show()
    sys.exit(app.exec_())
  1. 功能界面展示

由于功能界面比较复杂,不进行一一解释,我尽量在注释中描述比较清晰,如果想详细了解的请阅读代码function.py。 界面主要有以下几个关键部分

  • 缺陷图片显示及切换
  • 缺陷部位信息
  • 导入导出
  • 缩放关闭和软件名字

演示功能

  • 缺陷图片显示及切换

软件中有两处图片,上面的图片是整个部分的完整图片显示,用于用户在浏览时候能够准确知道当前的车身位置,类似于缩略图方式。(由多张图片拼接而成,划分区域的外边框是通过获取整个图片大小然后根据当前图片序号进行坐标定位的,所以可能会有稍微偏移) 下面的部分是当前的缺陷图片,原图像是2048*1400的大小,在软件中通过适当的处理,可以实现鼠标滚轮缩放和左键点击拖动。

  • 缺陷部位信息

这一部分展示了当前车部位的所有可能存在缺陷,点击对应的序号可以弹出存在缺陷的图片(可缩放查看),进行二次确认。

  • 导入导出

导入功能主要用于导入现有的文件夹,因为软件不实现检测功能(耗时较久,需要开多线程),所以开始按钮其实并无实际作用,这里采取延时几秒进行模拟仿真;导出主要是将确认后的缺陷结果写入本地文档中进行保存,可自己选择路径和命名。

  • 缩放关闭和软件名字

程序自带的缩放区域按钮较丑,所以自己实现了一个标题栏,将原来的边框进行隐藏,用到的方法是选择自己的图片,然后将对应的点击事件与槽函数进行衔接即可。

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

利用python的pyqt库实现一个简洁的pyqt5界面 展开 收起
Python
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/IIS_Chaser/Pyqt5-Interface-Function.git
git@gitee.com:IIS_Chaser/Pyqt5-Interface-Function.git
IIS_Chaser
Pyqt5-Interface-Function
Pyqt5-Interface-Function
master

搜索帮助