May-21-2019, 03:50 PM
Hello,i want to make a dependant combo boxes,where i basically choose 1 option from combobox1 and that option has its own set of options in combobox2. here,when i choose "Roman" from combobox1,i want it to populate other combobox with my already made list.
i keep searching and even though there are some explanations,i can't seem to make it work in my code.
i keep searching and even though there are some explanations,i can't seem to make it work in my code.
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.setEnabled(True) Form.resize(471, 392) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("iconfinder_Bleach_197477.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) Form.setWindowIcon(icon) self.label_author = QtWidgets.QLabel(Form) self.label_author.setEnabled(True) self.label_author.setGeometry(QtCore.QRect(340, 355, 121, 31)) font = QtGui.QFont() font.setFamily("Nimbus Mono L") font.setPointSize(9) self.label_author.setFont(font) self.label_author.setObjectName("label_author") self.label_1 = QtWidgets.QLabel(Form) self.label_1.setGeometry(QtCore.QRect(12, 42, 50, 22)) self.label_1.setObjectName("label_1") self.label_2 = QtWidgets.QLabel(Form) self.label_2.setGeometry(QtCore.QRect(12, 78, 34, 22)) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(Form) self.label_3.setGeometry(QtCore.QRect(12, 114, 34, 22)) self.label_3.setObjectName("label_3") self.label_4 = QtWidgets.QLabel(Form) self.label_4.setGeometry(QtCore.QRect(12, 150, 50, 22)) self.label_4.setObjectName("label_4") self.lineEdit_1 = QtWidgets.QLineEdit(Form) self.lineEdit_1.setGeometry(QtCore.QRect(68, 42, 142, 30)) self.lineEdit_1.setObjectName("lineEdit_1") self.lineEdit_2 = QtWidgets.QLineEdit(Form) self.lineEdit_2.setGeometry(QtCore.QRect(68, 78, 142, 30)) self.lineEdit_2.setObjectName("lineEdit_2") self.lineEdit_3 = QtWidgets.QLineEdit(Form) self.lineEdit_3.setGeometry(QtCore.QRect(68, 114, 142, 30)) self.lineEdit_3.setObjectName("lineEdit_3") self.lineEdit_4 = QtWidgets.QLineEdit(Form) self.lineEdit_4.setGeometry(QtCore.QRect(68, 150, 142, 30)) self.lineEdit_4.setObjectName("lineEdit_4") self.label = QtWidgets.QLabel(Form) self.label.setGeometry(QtCore.QRect(10, 360, 91, 22)) font = QtGui.QFont() font.setFamily("FreeMono") font.setBold(False) font.setItalic(True) font.setUnderline(False) font.setWeight(50) font.setStrikeOut(False) font.setKerning(True) self.label.setFont(font) self.label.setObjectName("label") self.line = QtWidgets.QFrame(Form) self.line.setGeometry(QtCore.QRect(11, 187, 227, 16)) self.line.setFrameShape(QtWidgets.QFrame.HLine) self.line.setFrameShadow(QtWidgets.QFrame.Sunken) self.line.setObjectName("line") self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(140, 355, 161, 31)) self.pushButton.setObjectName("pushButton") self.label_5 = QtWidgets.QLabel(Form) self.label_5.setGeometry(QtCore.QRect(10, 211, 43, 31)) self.label_5.setObjectName("label_5") self.lineEdit_5 = QtWidgets.QLineEdit(Form) self.lineEdit_5.setGeometry(QtCore.QRect(70, 210, 141, 30)) self.lineEdit_5.setReadOnly(True) self.lineEdit_5.setObjectName("lineEdit_5") self.line_2 = QtWidgets.QFrame(Form) self.line_2.setGeometry(QtCore.QRect(10, 260, 227, 16)) self.line_2.setFrameShape(QtWidgets.QFrame.HLine) self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_2.setObjectName("line_2") self.line_3 = QtWidgets.QFrame(Form) self.line_3.setEnabled(True) self.line_3.setGeometry(QtCore.QRect(230, 10, 16, 258)) self.line_3.setLineWidth(1) self.line_3.setMidLineWidth(0) self.line_3.setFrameShape(QtWidgets.QFrame.VLine) self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken) self.line_3.setObjectName("line_3") self.comboBox_2 = QtWidgets.QComboBox(Form) self.comboBox_2.setGeometry(QtCore.QRect(360, 40, 86, 30)) self.comboBox_2.setObjectName("comboBox") self.comboBox = QtWidgets.QComboBox(Form) self.comboBox.setGeometry(QtCore.QRect(250, 40, 86, 30)) self.comboBox.setObjectName("comboBox_2") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") self.label_6 = QtWidgets.QLabel(Form) self.label_6.setGeometry(QtCore.QRect(260, 10, 68, 22)) self.label_6.setAlignment(QtCore.Qt.AlignCenter) self.label_6.setObjectName("label_6") self.label_7 = QtWidgets.QLabel(Form) self.label_7.setGeometry(QtCore.QRect(370, 10, 68, 22)) self.label_7.setAlignment(QtCore.Qt.AlignCenter) self.label_7.setWordWrap(False) self.label_7.setObjectName("label_7") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): _translate = QtCore.QCoreApplication.translate Form.setWindowTitle(_translate("Form", "UNI-TRAV Calculator")) self.label_author.setText(_translate("Form", "Version: 1.0.0")) self.label_1.setText(_translate("Form", "Wood: ")) self.label_2.setText(_translate("Form", "Clay:")) self.label_3.setText(_translate("Form", "Iron:")) self.label_4.setText(_translate("Form", "Wheat:")) self.label.setText(_translate("Form", "Hitsugaya")) self.pushButton.setText(_translate("Form", "Magic Button")) self.label_5.setText(_translate("Form", "Total: ")) self.lineEdit_5.setText(_translate("Form", "0")) self.comboBox.setItemText(0, _translate("Form", "Romans")) self.comboBox.setItemText(1, _translate("Form", "Gauls")) self.comboBox.setItemText(2, _translate("Form", "Teutons")) self.label_6.setText(_translate("Form", "Tribe:")) self.label_7.setText(_translate("Form", "Unit:")) self.pushButton.clicked.connect(self.klik) Romans = ["Leggionaire", "Praetorian", "Imperian", "Equites Legati", "Equites Imperatoris", "Equites Caesaris", "Battering Ram", "Fire Catapult", "Senator", "Settler"] Gauls = ["Phalanx", "Swordsman", "Pathfinder", "Theutates Thunder", "Druidrider", "Haeduan", "Ram", "Trebuchet", "Chieftain", "Settler"] Teutons = ["Clubswinger", "Spearman", "Axeman", "Scout", "Paladin", "Teutonic Knight", "Ram", "Catapult", "Chief", "Settler"] def klik(self): textbox1 = self.lineEdit_1.text() textbox2 = self.lineEdit_2.text() textbox3 = self.lineEdit_3.text() textbox4 = self.lineEdit_4.text() self.lineEdit_5.setText(str(int(textbox1) + int(textbox2) + int(textbox3) + int(textbox4))) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) Form.show() sys.exit(app.exec_())