jeudi 20 mai 2021

How to get combobox.currentText () value

from form import Ui_Dialog
from PyQt5 import QtCore, QtWidgets


class MainWindow(Ui_Dialog):
    def __init__(self):
        super(MainWindow).__init__()

    def setupUi(self, Dialog):
        super(MainWindow, self).setupUi(Dialog)
        self.btn_print.clicked.connect(lambda: print_doc())


class Ui_Dialog_combobox(object):  
    def __init__(self):
        super(MainWindow).__init__()
        self.comboBox = QtWidgets.QComboBox(Dialog)
        self.comboBox.setGeometry(QtCore.QRect(458, 10, 151, 22))
        self.comboBox.setObjectName("comboBox_doctor")
        self.comboBox.addItem("")
        self.retranslateUi(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.comboBox.setItemText(0, _translate("Dialog", "NAME"))


def print_doc():
    name = ui.comboBox.currentText()
    print(name)
    # Process finished with exit code -1073740791 (0xC0000409)


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    Ui_Dialog_combobox()
    ui = MainWindow()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())



Aucun commentaire:

Enregistrer un commentaire