• Python+Qt多点最短路径(最优路径)算法实现


    程序示例精选
    Python+Qt多点最短路径(最优路径)算法实现
    如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

    前言

    这篇博客针对《Python+Qt多点最短路径(最优路径)算法实现》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。


    运行结果

    在这里插入图片描述


    文章目录

    一、所需工具软件
    二、使用步骤
           1. 主要代码
           2. 运行结果
    三、在线协助

    一、所需工具软件

           1. Qt
           2.Python

    二、使用步骤

    代码如下(示例):
    
    # coding:utf-8
    import sys
    #从转换的.py文件内调用类
    import cv2
    
    from PyQt5 import QtWidgets
    
    from PyQt5 import QtWidgets, QtCore, QtGui
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    import floyd
    
    
    global imgName
    global imgT
    imgT=[]
    
    
    
    from PyQt5 import QtCore, QtGui, QtWidgets
    
    
    class Ui_Dialog(object):
        def setupUi(self, Dialog):
            Dialog.setObjectName("Dialog")
            Dialog.resize(579, 501)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
            Dialog.setSizePolicy(sizePolicy)
            self.gridLayout_2 = QtWidgets.QGridLayout(Dialog)
            self.gridLayout_2.setObjectName("gridLayout_2")
            self.frame = QtWidgets.QFrame(Dialog)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
            sizePolicy.setHorizontalStretch(5)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
            self.frame.setSizePolicy(sizePolicy)
            self.frame.setFrameShape(QtWidgets.QFrame.Box)
            self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
            self.frame.setObjectName("frame")
            self.gridLayout = QtWidgets.QGridLayout(self.frame)
            self.gridLayout.setObjectName("gridLayout")
            self.label = QtWidgets.QLabel(self.frame)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(1)
            sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
            self.label.setSizePolicy(sizePolicy)
            self.label.setStyleSheet("background-color: rgb(255, 255, 255);")
            self.label.setAlignment(QtCore.Qt.AlignCenter)
            self.label.setObjectName("label")
            self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
            self.gridLayout_2.addWidget(self.frame, 0, 1, 5, 1)
            self.frame_2 = QtWidgets.QFrame(Dialog)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
            sizePolicy.setHorizontalStretch(1)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.frame_2.sizePolicy().hasHeightForWidth())
        sizePolicy.setHeightForWidth(self.textEdit.sizePolicy().hasHeightForWidth())
            self.textEdit.setSizePolicy(sizePolicy)
            self.textEdit.setMinimumSize(QtCore.QSize(0, 150))
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(16)
            self.textEdit.setFont(font)
            self.textEdit.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
            self.textEdit.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
            self.textEdit.setObjectName("textEdit")
            self.gridLayout_3.addWidget(self.textEdit, 6, 0, 1, 1)
            spacerItem = QtWidgets.QSpacerItem(17, 130, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
            self.gridLayout_3.addItem(spacerItem, 7, 0, 1, 1)
            self.pushButton = QtWidgets.QPushButton(self.frame_2)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
            sizePolicy.setHorizontalStretch(1)
            sizePolicy.setVerticalStretch(0)
            sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
            self.pushButton.setSizePolicy(sizePolicy)
            font = QtGui.QFont()
            font.setFamily("微软雅黑")
            font.setPointSize(16)
            font.setBold(False)
            font.setWeight(50)
            self.pushButton.setFont(font)
            self.pushButton.setObjectName("pushButton")
            self.gridLayout_3.addWidget(self.pushButton, 0, 0, 1, 1)
            self.pushButton_3 = QtWidgets.QPushButton(self.frame_2)
            sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
            sizePolicy.setHorizontalStretch(0)
            sizePolicy.setVerticalStretch(0)
      
    class myWin(QtWidgets.QWidget, Ui_Dialog):
    
        def __init__(self):
            super(myWin, self).__init__()
            self.setupUi(self)
            self.pushButton_2.hide()
        def openFileButton(self):
            global imgName
            imgName, imgType  = QFileDialog.getOpenFileName(self,"打开文件","./","files(*.*)")
            frame = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
            height, width, bytesPerComponent = frame.shape
            self.q_image = QtGui.QImage(frame.data,bytesPerLine, QtGui.QImage.Format_RGB888).scaled(
            self.update()
        def saveFileButton(self):
            print("test")
        def recogPerson(self):
            self.textEdit.clear()
            # source = 1
            # destination = 0
            source=self.comboBox.currentText()
            destination=self.comboBox_2.currentText()
            print("source",source)
            print("destination",destination)
            source=int(source)
            destination = int(destination)
       self.textEdit.append("从"+str(source)+"到"+str(destination)+"的最短距离是 "+str(floyd.shortest_distances[source][destination]))
            self.textEdit.append("路径: "+str(floyd.print_path(floyd.next_nodes, source, destination)))
    if __name__=="__main__":
        import sys
        QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
        app=QtWidgets.QApplication(sys.argv)
        Widget=myWin()
        Widget.showMaximized();
        Widget.show()
        sys.exit(app.exec_())
    
    
    • 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
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    运行结果

    在这里插入图片描述

    三、在线协助:

    如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!

    1)远程安装运行环境,代码调试
    2)Visual Studio, Qt, C++, Python编程语言入门指导
    3)界面美化
    4)软件制作
    5)云服务器申请
    6)网站制作

    当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
    个人博客主页https://blog.csdn.net/alicema1111?type=blog
    博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog

    博主推荐:
    Python人脸识别考勤打卡系统:
    https://blog.csdn.net/alicema1111/article/details/133434445
    Python果树水果识别https://blog.csdn.net/alicema1111/article/details/130862842
    Python+Yolov8+Deepsort入口人流量统计:https://blog.csdn.net/alicema1111/article/details/130454430
    Python+Qt人脸识别门禁管理系统:https://blog.csdn.net/alicema1111/article/details/130353433
    Python+Qt指纹录入识别考勤系统:https://blog.csdn.net/alicema1111/article/details/129338432
    Python Yolov5火焰烟雾识别源码分享:https://blog.csdn.net/alicema1111/article/details/128420453
    Python+Yolov8路面桥梁墙体裂缝识别:https://blog.csdn.net/alicema1111/article/details/133434445

  • 相关阅读:
    vue组件缓存
    菜鸟先飞之初识Hive、安装教程及常见问题
    腾讯云大数据ES Serverless
    没有专业背景,还有机会成为机器学习工程师吗?
    Unity记录5.4-地图-带种子的柏林噪声
    Spring-boot运行原理(Pom.xml)
    Scala
    勇士大战恶魔?这款桌游明明是套高质量原创手办
    一举两得:研究发现常吃辣椒可延长寿命和抵御寒冷
    425.响应式的境外旅游私人订制网站 大学生期末大作业 Web前端网页制作 html+css+js
  • 原文地址:https://blog.csdn.net/alicema1111/article/details/134400545