普通螺纹基本牙型尺寸及拧紧力矩.exe

一、概要

普通螺纹基本牙型尺寸及拧紧力矩.exe_第1张图片

普通螺纹基本牙型尺寸及拧紧力矩.exe_第2张图片

  本软件功能主要是通过输入螺纹原始三角形高度P,螺栓规格(公称直径)d,材料的屈服应力σs,计算出公称应力截面积As、外螺纹小径d1、外螺纹小径d2、拧紧力矩T等参数。

  开发本软件的原因主要有以下几点:

  1. 提高设计效率:通过这款软件,工程师可以快速计算螺纹的基本牙型尺寸和拧紧力矩,减少繁琐的手动计算,提高设计效率。
  2. 增强设计准确性:该软件基于严谨的数学模型和算法进行计算,避免了手动计算可能出现的错误,提高了设计的准确性。
  3. 方便易用:该软件具备友好的用户界面,使得用户可以便捷地进行操作,输入参数即可得到结果,省去了繁琐的手动计算过程。

二、技术细节

  这段代码中主要完成的任务有:

  1. 读取用户输入的一些参数(例如螺纹的原始三角形高度P,螺栓规格(公称直径)d,材料的屈服应力σs等)。
  2. 计算螺纹的原始三角形高度P,外螺纹的小径d1,中径d2,以及螺栓的公称应力截面积As。
  3. 根据这些计算结果,进一步计算拧紧力矩T。
  4. 将所有的计算结果以特定格式(保留指定位数的小数)显示给用户。

  代码技术细节:

  • self.significant_digit_lineEdit.text():从用户界面获取需要保留的有效数字位数。
  • float(self.P_lineEdit.text())float(self.d_lineEdit.text())float(self.s_lineEdit.text()):从用户界面读取输入的参数值,转换为浮点数。
  • math.sqrt(3):开平方根运算。
  • "{:.{}f}".format(H, int(self.significant_digit_lineEdit.text())):格式化输出,保留指定位数的小数。例如,如果用户输入要保留的位数为3,那么P会被格式化为类似"3.142"这样的形式。
  • self.d1_lineEdit.setText(...)self.d2_lineEdit.setText(...)self.A_lineEdit.setText(...)self.T_lineEdit.setText(...)等:将这些计算结果显示给用户。

三、完整代码

软件开发所用到的excel表和icon图标均已打包:statics

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2023-10-14 14:57
# @Author : Leuanghing Chen
# @Blog : https://blog.csdn.net/weixin_46153372?spm=1010.2135.3001.5421
# @File : 普通螺纹基本牙型尺寸及拧紧力矩.py
# @Software : PyCharm
# pyinstaller --clean -y -w --icon D:\python_demo\2、普通螺纹基本牙型尺寸及拧紧力矩\螺丝大图标.ico D:\python_demo\2、普通螺纹基本牙型尺寸及拧紧力矩\screw.py
# 打包好程序后将icon和statics文件夹复制到程序所在文件夹中

import math
import multiprocessing
import sys
from html import unescape
from openpyxl import load_workbook
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QDialog, QVBoxLayout, QTableWidget, QTableWidgetItem


# 主界面
class Ui_MainWindow(QMainWindow):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(680, 310)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(680, 310))
        MainWindow.setMaximumSize(QtCore.QSize(680, 310))
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(12)
        MainWindow.setFont(font)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("./icon/螺丝小图标.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        MainWindow.setStyleSheet("background-color: rgb(255, 255, 255);\n"
                                 "color: rgb(0, 0, 0);")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.d1_unit_label = QtWidgets.QLabel(self.centralwidget)
        self.d1_unit_label.setGeometry(QtCore.QRect(306, 57, 40, 30))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.d1_unit_label.sizePolicy().hasHeightForWidth())
        self.d1_unit_label.setSizePolicy(sizePolicy)
        self.d1_unit_label.setMinimumSize(QtCore.QSize(40, 30))
        self.d1_unit_label.setMaximumSize(QtCore.QSize(40, 30))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.d1_unit_label.setFont(font)
        self.d1_unit_label.setObjectName("d1_unit_label")
        self.Units_textEdit = QtWidgets.QTextEdit(self.centralwidget)
        self.Units_textEdit.setEnabled(False)
        self.Units_textEdit.setGeometry(QtCore.QRect(380, 25, 265, 50))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.Units_textEdit.sizePolicy().hasHeightForWidth())
        self.Units_textEdit.setSizePolicy(sizePolicy)
        self.Units_textEdit.setMinimumSize(QtCore.QSize(265, 50))
        self.Units_textEdit.setMaximumSize(QtCore.QSize(265, 50))
        self.Units_textEdit.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.Units_textEdit.setStyleSheet("background-color: rgb(255, 255, 127);")
        self.Units_textEdit.setObjectName("Units_textEdit")
        self.A_unit_label = QtWidgets.QLabel(self.centralwidget)
        self.A_unit_label.setGeometry(QtCore.QRect(306, 21, 40, 30))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.A_unit_label.sizePolicy().hasHeightForWidth())
        self.A_unit_label.setSizePolicy(sizePolicy)
        self.A_unit_label.setMinimumSize(QtCore.QSize(40, 30))
        self.A_unit_label.setMaximumSize(QtCore.QSize(40, 30))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.A_unit_label.setFont(font)
        self.A_unit_label.setObjectName("A_unit_label")
        self.A_lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.A_lineEdit.setEnabled(False)
        self.A_lineEdit.setGeometry(QtCore.QRect(200, 21, 100, 30))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.A_lineEdit.sizePolicy().hasHeightForWidth())
        self.A_lineEdit.setSizePolicy(sizePolicy)
        self.A_lineEdit.setMinimumSize(QtCore.QSize(90, 30))
        self.A_lineEdit.setMaximumSize(QtCore.QSize(100, 30))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.A_lineEdit.setFont(font)
        self.A_lineEdit.setStyleSheet("background-color: rgb(85, 255, 255);")
        self.A_lineEdit.setText("")
        self.A_lineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.A_lineEdit.setObjectName("A_lineEdit")
        self.Vertical_line = QtWidgets.QFrame(self.centralwidget)
        self.Vertical_line.setGeometry(QtCore.QRect(352, 10, 16, 223))
        self.Vertical_line.setFrameShape(QtWidgets.QFrame.VLine)
        self.Vertical_line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.Vertical_line.setObjectName("Vertical_line")
        self.A_label = QtWidgets.QLabel(self.centralwidget)
        self.A_label.setGeometry(QtCore.QRect(10, 21, 190, 30))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.A_label.sizePolicy().hasHeightForWidth())
        self.A_label.setSizePolicy(sizePolicy)
        self.A_label.setMinimumSize(QtCore.QSize(190, 30))
        self.A_label.setMaximumSize(QtCore.QSize(180, 30))
        font = QtGui.QFont()
        font.setFamily("楷体")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.A_label.setFont(font)
        self.A_label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
        self.A_label.setObjectName("A_label")
        self.horizontal_line_1 = QtWidgets.QFrame(self.centralwidget)
        self.horizontal_line_1.setGeometry(QtCore.QRect(5, 5, 670, 10))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.horizontal_line_1.sizePolicy().hasHeightForWidth())
        self.horizontal_line_1.setSizePolicy(sizePolicy)
        self.horizontal_line_1.setMinimumSize(QtCore.QSize(670, 10))
        self.horizontal_line_1.setMaximumSize(QtCore.QSize(670, 10))
        self.horizontal_line_1.setFrameShape(QtWidgets.QFrame.HLine)
        self.horizontal_line_1.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.horizontal_line_1.setObjectName("horizontal_line_1")
        self.H_lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.H_lineEdit.setEnabled(False)
        self.H_lineEdit.setGeometry(QtCore.QRect(200, 122, 100, 30))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.H_lineEdit.sizePolicy().hasHeightForWidth())
        self.H_lineEdit.setSizePolicy(sizePolicy)
        self.H_lineEdit.setMinimumSize(QtCore.QSize(90, 30))
        self.H_lineEdit.setMaximumSize(QtCore.QSize(100, 30))
        font = QtGui.QFont()
        font.setFamily("Times New Roman")
        font.setPointSize(14)
        self.H_lineEdit.setFont(font)
        self.H_lineEdit.setStyleSheet("background-color: rgb(85, 255, 255);")
        self.H_lineEdit.setText("")
        self.H_lineEdit.setAlignment(QtCore.Qt.AlignCenter)
        self.H_lineEdit.setObjectName("H_lineEdit")
        self.H_label = QtWidgets.QLabel(self.centralwidget)
        self.H_label.setGeometry(QtCore.QRect(10, 122, 190, 30))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.H_label.sizePolicy().hasHeightForWidth())
        self.H_label.setSizePolicy(sizePolicy)
        self.H_label.setMinimumSize(QtCore.QSize(190, 30))
        self.H_label.setMaximumSize(QtCore.QSize(180, 30))
        font = QtGui.QFont()
        font.setFamily("楷体")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        self.H_label.setFont(font)
        self.H_label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
        self.H_label.setObjectName("H_label")
        self.d2_lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.d2_lineEdit.setEnabled(False)
        self.d2_lineEdit.setGeometry(QtCore.QRect(200, 89, 100, 30))
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.

你可能感兴趣的:(python,螺纹拧紧力矩,exe)