Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5.QtCore import pyqtSlot
- from PyQt5.QtWidgets import QApplication, QWidget, QComboBox, QVBoxLayout
- class MainWindow(QWidget):
- def __init__(self, parent=None):
- super().__init__(parent)
- self._items = {
- "a": ["1", "2", "3"],
- "b": ["a", "b", "b"],
- }
- self._combobox_1 = QComboBox()
- self._combobox_2 = QComboBox()
- self._combobox_1.addItems(self._items.keys())
- layout = QVBoxLayout()
- layout.addWidget(self._combobox_1)
- layout.addWidget(self._combobox_2)
- self._handle_item_change()
- self.setLayout(layout)
- self._combobox_1.activated.connect(self._handle_item_change)
- @pyqtSlot()
- def _handle_item_change(self):
- self._combobox_2.clear()
- self._combobox_2.addItems(self._items[self._combobox_1.currentText()])
- app = QApplication(sys.argv)
- window = MainWindow()
- window.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement