import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QAction, qApp from PyQt5.QtGui import QIcon class Example(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): exitAction = QAction(QIcon("C:\\Users\\hengli\\Pictures\\CameraMan\\ss.jpg"), '&退出', self) exitAction.setShortcut('Ctrl+Q') #设置快捷键 exitAction.setStatusTip('退出应用') #设置状态栏信息 exitAction.triggered.connect(qApp.quit) self.statusBar() menubar = self.menuBar() fileMenu = menubar.addMenu('&文件') fileMenu.addAction(exitAction) self.setGeometry(300, 300, 300, 200) self.setWindowTitle('菜单栏') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit((app.exec_()))
原文地址:http://blog.csdn.net/u013511642/article/details/45342995