使用ComboBox,PyQT做出选择

时间:2014-04-22 10:28:12

标签: pyqt

你好吗?

我只是想创建一个程序,其中建议选择Combobox。

例如,如果您在ComboBox中选择一个项目,它将在Spinbox中写入。 但我的问题是,在第三个Spinbox中没有创建一个新的Combobox。

希望你理解

检查出来:))

`

# -*- coding: utf-8 -*-
import sys
from PyQt4.QtCore import Qt
from PyQt4.QtGui import (QApplication, QWidget, QVBoxLayout, QSpinBox, QComboBox)



class Widget(QWidget):
    def __init__(self):
        super(Widget, self).__init__()
        self.layout = QVBoxLayout(self)
        self.spin = QSpinBox(self)
        self.spin2 = QSpinBox(self)
        self.spin3 = QSpinBox(self)

        self.combo = QComboBox(self)
        self.combo2 = QComboBox(self)

        self.layout.addWidget(self.spin)
        self.layout.addWidget(self.spin2)
        self.layout.addWidget(self.spin3)
        self.layout.addWidget(self.combo)
        self.layout.addWidget(self.combo2)

        self.combo.currentIndexChanged['QString'].connect(self.on_combo_changed)
        self.combo2.currentIndexChanged['QString'].connect(self.changed)


        self.data = {"HANDSET1": 5,"HANDSET": 6, "HANDFREE": 10, "CAR KIT": 15, "RSM": 20}
        self.dodo = {"HANDSET1": 44, "HANDSET": 76, "HANDFREE": 1, "CAR KIT": 7, "RSM": 0}
        self.coco = {"HANDSET1": 0, "HANDSET": 7, "HANDFREE": 11, "CAR KIT": 77, "RSM": 10} # How to put this function, without create a other ComboBox ?

        self.combo.addItems(self.data.keys())
        self.combo2.addItems(self.dodo.keys())


    def on_combo_changed(self, txt):
        self.spin.setValue(self.data[unicode(txt)])
    def changed(self, txt):
        self.spin2.setValue(self.coco[unicode(txt)])

if __name__ == '__main__':
    app = QApplication([])
    w = Widget()
    w.show()
    sys.exit(app.exec_())

`

0 个答案:

没有答案