5. PyQt6 菜单栏
2023-10-17 python 328
import sys from PyQt6.QtWidgets import QApplication, QMainWindow from PyQt6.QtGui import QGuiApplication, QAction, QIcon class App(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle("PyQt6 窗口案例") exitAct = QAction(QIcon("exit.png"), "&退出", self) exitAct.setShortcut("Ctrl+Q") exitAct.setStatusTip("退出应用") exitAct.triggered.connect(QApplication.instance().quit) self.statusBar() menubar = self.menuBar() file_menu = menubar.addMenu("文件") file_menu.addAction(exitAct) self.setGeometry(100, 100, 400, 300) self.center() 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条评论