Answer the question
In order to leave comments, you need to log in
How to get the selected value of a QComboBox in Python?
Hello. Can you please explain to me how accessing a QComboBox and getting the selected value from it works?
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from gui import Ui_MainWindow # Здесь подключается UI формы
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
comboValue = 0
def installer():
- - - - # Здесь я хочу проверить выбранное значение ui.comboBox и записать в переменную comboValue = 1
- - - - print(comboValue)
ui.pushButton_search.clicked.connect( installer ) # Нажатие на кнопку установить
Answer the question
In order to leave comments, you need to log in
QComboBox has wonderful methods: ui.comboBox.currentText()
ui.comboBox.currentData()
, which return the text or data associated with the given value, respectively. No signals are needed to use them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question