小白是真白啊 2021-09-11 08:31
浏览 347
已结题

PyQt5 lable 显示 DoubleSpinBox 值时小数精度问题

请问,PyQt5 lable 显示 DoubleSpinBox 值时小数精度问题,到0.009以后就异常了,求指导


 -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'DoubleSpinBox.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# 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.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(532, 170)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.doubleSpinBox = QtWidgets.QDoubleSpinBox(self.centralwidget)
        self.doubleSpinBox.setGeometry(QtCore.QRect(100, 40, 351, 31))
        self.doubleSpinBox.setDecimals(3)
        self.doubleSpinBox.setMinimum(0)
        self.doubleSpinBox.setMaximum(99.999)
        self.doubleSpinBox.setSingleStep(0.001)
        self.doubleSpinBox.setStepType(QtWidgets.QAbstractSpinBox.DefaultStepType)
        self.doubleSpinBox.setObjectName("doubleSpinBox")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(100, 90, 131, 16))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(230, 90, 211, 16))
        self.label_2.setText("")
        self.label_2.setObjectName("label_2")
        self.doubleSpinBox.valueChanged.connect(self.getvalue)
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "当前控件中显示的数值:"))

    def getvalue(self):
        self.label_2.setText(str(self.doubleSpinBox.value()))


import sys #程序入口,从此处启动PyQt设计窗体
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()    #创建窗体对象
    ui = Ui_MainWindow()                   # 创建 PYQT 设计的窗体对象
    ui.setupUi(MainWindow)                 # 调用Pyqt窗口方法,对窗体对象初始化设置。
    MainWindow.show()                      # 显示窗体
    sys.exit(app.exec_())                  # 退出结束进程

img

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 9月19日
    • 创建了问题 9月11日

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 MATLAB动图问题
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名