# Import necessary packages from PyQt5.QtWidgets import QApplication, QComboBox, QWidget, QVBoxLayout import sys # Create the application and widget app = QApplication(sys.argv) widget = QWidget() # Create a QComboBox and add options combo = QComboBox() combo.addItem("Option 1") combo.addItem("Option 2") combo.addItem("Option 3") # Add the widget to a layout and show the widget layout = QVBoxLayout() layout.addWidget(combo) widget.setLayout(layout) widget.show() # Run the application sys.exit(app.exec_())
# Import necessary packages from PyQt5.QtWidgets import QApplication, QComboBox, QWidget, QVBoxLayout, QLabel import sys # Create the application and widget app = QApplication(sys.argv) widget = QWidget() # Create a QComboBox and add options combo = QComboBox() combo.addItem("Option 1") combo.addItem("Option 2") combo.addItem("Option 3") # Create a label to display the selected option label = QLabel() # Connect the QComboBox signal to update the label combo.currentIndexChanged.connect(lambda: label.setText(combo.currentText())) # Add the widget and label to a layout and show the widget layout = QVBoxLayout() layout.addWidget(combo) layout.addWidget(label) widget.setLayout(layout) widget.show() # Run the application sys.exit(app.exec_())In both examples, the package library being used is PyQt5.Qt.