30. PyQt6 QComboBox
2023-10-17 python 938
import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QComboBox from PyQt6.QtGui import QGuiApplication class App(QMainWindow): def __init__(self): super().__init__() self.lbl = None self.initUI() def initUI(self): self.setWindowTitle("PyQt6 QComboBox") self.lbl = QLabel("Ubuntu", self) combo = QComboBox(self) combo.addItem("Ubuntu") combo.addItem("Mandriva") combo.addItem("Fedora") combo.addItem("Arch") combo.addItem("Gentoo") combo.move(50, 50) combo.textActivated[str].connect(self.onActivated) self.setGeometry(100, 100, 400, 300) self.center() def onActivated(self, text): self.lbl.setText(text) self.lbl.adjustSize() def center(self): qr = self.frameGeometry() cp = QGuiApplication.primaryScreen().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) if __name__ == "__main__": app = QApplication(sys.argv) cls_app = App() cls_app.show() sys.exit(app.exec())
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论