Python Forum

Full Version: Get Data from QComboBox
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good day to everyone!
How can I get value of QComboBox? Cause from currentText() I only get my first value. In the internet i found examples where value prints in the function, but I need to get value for the next function.
And is it possible at all?

Thanks in advance. Sorry for gramma.

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QComboBox, QPushButton


class Example(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):
        lbl1 = QLabel('Example:', self)
        lbl1.move(15, 10)
        combo = QComboBox(self)
        combo.addItems(["11", "22", "33"])
        combo.move(70, 8)
        combo.activated[str].connect(self.onActivated)   # Reassign Qlabel
        currText = combo.currentText()  # But how to reassing currText



        self.lbl2 = QLabel('11', self)
        self.lbl2.move(15, 50)

        self.btn = QPushButton("go", self)
        self.btn.move(100, 50)
        self.btn.clicked.connect(lambda: self.doCalc(currText))


        self.setGeometry(300, 300, 200, 100)
        self.setWindowTitle("Application")
        self.show()



    def onActivated(self, text):
        self.lbl2.setText(text)
        self.lbl2.adjustSize()

    def doCalc(self, text):
        print("work", text)


if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())