from PyQt5.QtWidgets import QApplication,QMainWindow,qApp,QAction
from PyQt5.QtGui import QIcon
import sys
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
exitAction = QAction(QIcon('python\day09\exit3.png'),'退出',self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
# 创建工具栏
toolBar = self.addToolBar('工具栏')
toolBar.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_())
from PyQt5.QtWidgets import QApplication,QMainWindow,qApp,QAction
from PyQt5.QtGui import QIcon
import sys
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 创建一个菜单条目
exitAction = QAction(QIcon('python\day09\exit3.png'),'退出',self)
# 添加快捷键
exitAction.setShortcut('Ctrl+Q')
# 添加一个提示
exitAction.setStatusTip('退出程序!')
# 给菜单条目添加动作
exitAction.triggered.connect(qApp.quit)
# 创建一个菜单栏
menuBar = self.menuBar()
# 添加一个File菜单
fileMenu = menuBar.addMenu('File')
# 添加菜单条目
fileMenu.addAction(exitAction)
editMenu = menuBar.addMenu('Edit')
editMenu.addAction(exitAction)
self.setGeometry(300,300,300,200)
self.setWindowTitle('程序菜单')
self.show()
|