# QMenuBar/QMenu/QAction的使用(菜单栏) from PyQt5.QtWidgets import * from PyQt5.QtCore import QDir from PyQt5.QtGui import QIcon, QPixmap, QFont from PyQt5.QtCore import QDate import sys class MainForm(QMainWindow): def __init__(self, parent=None): super(MainForm, self).__init__(parent) self.setFixedSize(500, 500) self.layout = QHBoxLayout() self.menubar = self.menuBar() # 获取窗体的菜单栏 self.file = self.menubar.addMenu("菜单") self.file.addAction("新建") self.save = QAction("保存", self) self.save.setShortcut("Ctrl+S") # 设置快捷键 self.file.addAction(self.save) self.edit = self.file.addMenu("方向") self.edit.addAction("上") self.edit.addAction("下") self.quit = QAction("退出", self) self.file.addAction(self.quit) self.file.triggered[QAction].connect(self.process_trigger) self.setLayout(self.layout) self.setWindowTitle("菜单的使用") def process_trigger(self, qaction): print(qaction.text() + "触发") if __name__ == "__main__": app = QApplication(sys.argv) mainForm = MainForm() mainForm.show() sys.exit(app.exec_())
来源:CSDN
作者:云未归来
链接:https://blog.csdn.net/FL1623863129/article/details/103482320