I've got the following code, and after sieving through the answers on StackOverflow, I can't manage to adapt them to my (very simple) code. This creates a window with two drop downs (one selecting a month, and the other a year) and a button to commence the rest of the script.
I need to store the "selection" of the Combo Box in a global variable for use in the rest of the script.
I'm not sure if this is the most elegantly written, or even the best way to do this.
I'm not sure if I need to encapsulate this in a class of some sort, but I've had no luck so far. The code below currently just returns the starting text, rather than user-selected text in the dropdown.
def runapp():
def on_button_clicked():
startprocessing()
app = QApplication([])
app.setStyle('Fusion')
window = QWidget()
layout = QVBoxLayout()
combobox_month = QComboBox()
combobox_year = QComboBox()
progress = QLabel('Test')
layout.addWidget(progress)
layout.addWidget(combobox_month)
layout.addWidget(combobox_year)
combobox_month.addItems(calendar.month_name)
combobox_year.addItems(['2017', '2018', '2019'])
processbutton = QPushButton('Process')
layout.addWidget(processbutton)
global month
month = str(combobox_month.currentText())
global year
year = str(combobox_year.currentText())
processbutton.clicked.connect(on_button_clicked)
window.setLayout(layout)
window.show()
app.exec_()