9. PyQt6 主窗口
2023-10-17 python 353
import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QTextEdit from PyQt6.QtGui import QGuiApplication, QIcon, QAction class App(QMainWindow): def __init__(self): super().__init__() self.toolbar = None self.initUI() def initUI(self): self.setWindowTitle("PyQt6 主窗口") exit_act = QAction(QIcon("exit.png"), "退出", self) exit_act.setShortcut("Ctrl+Q") exit_act.triggered.connect(QApplication.instance().quit) self.toolbar = self.addToolBar("退出") self.toolbar.addAction(exit_act) text_edit = QTextEdit() self.setCentralWidget(text_edit) 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条评论