Python2 + PyQt5:如何获得QDoubleSpinBox的价值?

时间:2017-12-17 13:59:33

标签: python qt pyqt pyqt5

我想问一下如何获取QDoubleSpinBox的值。它让我感到困惑是一个新用户。 Hier是我的代码:

# -*- coding: utf-8 -*-

from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QDoubleSpinBox

import sys

class MyApp(QWidget):
    def __init__(self, parent=None):
        super(MyApp, self).__init__(parent)

        dsbox = QDoubleSpinBox(self)
        dsbox.setDecimals(1)
        dsbox.setValue(100.00)
        dsbox.setMinimum(1.00)
        dsbox.setMaximum(3500.00)
        dsbox.setSingleStep(1.00)
        dsbox.setSuffix("mm")

        dsbox.valueChanged.connect(self.on_value_changed)

        self.show()

    def on_value_changed(self):
        print "You are now in the sub function."
        print self.dsbox.value() #Problem is hier

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyApp()
    sys.exit(app.exec_())

结果是:

You are now in the sub function.

Process finished with exit code 1

这意味着这一行有问题:print self.dsbox.value()

我已经检查过QDoubleSpinBox类有一个“值”公共函数: AtomicReference

那么我做错了什么呢?谢谢你的帮助!

0 个答案:

没有答案