请问,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_()) # 退出结束进程