Advertisement
Guest User

Hovna

a guest
Jan 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import sys
  2.  
  3. from PyQt5.QtCore import pyqtSlot
  4. from PyQt5.QtWidgets import QApplication, QWidget, QComboBox, QVBoxLayout
  5.  
  6.  
  7. class MainWindow(QWidget):
  8.     def __init__(self, parent=None):
  9.         super().__init__(parent)
  10.  
  11.         self._items = {
  12.             "a": ["1", "2", "3"],
  13.             "b": ["a", "b", "b"],
  14.         }
  15.  
  16.         self._combobox_1 = QComboBox()
  17.         self._combobox_2 = QComboBox()
  18.  
  19.         self._combobox_1.addItems(self._items.keys())
  20.  
  21.         layout = QVBoxLayout()
  22.         layout.addWidget(self._combobox_1)
  23.         layout.addWidget(self._combobox_2)
  24.         self._handle_item_change()
  25.  
  26.         self.setLayout(layout)
  27.  
  28.         self._combobox_1.activated.connect(self._handle_item_change)
  29.  
  30.     @pyqtSlot()
  31.     def _handle_item_change(self):
  32.         self._combobox_2.clear()
  33.         self._combobox_2.addItems(self._items[self._combobox_1.currentText()])
  34.  
  35.  
  36. app = QApplication(sys.argv)
  37.  
  38. window = MainWindow()
  39. window.show()
  40.  
  41. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement