我的账户
啄木鸟学院

专注软件测试菁英教育

亲爱的游客,欢迎!

已有账号,请

如尚未注册?

吕煜海2021/1/27

[复制链接]
亲爱的葡萄 发表于 2021-1-27 19:55:56 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
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()






回复

使用道具 举报

关注0

粉丝0

帖子8

发布主题
大家都在学
课堂讨论
一周热帖排行最近7x24小时热帖
关注我们
专注软件测试菁英教育

客服电话:17792550360

客服时间:9:00-21:00

卓目鸟学苑 - 专注软件测试菁英教育!( 陕ICP备20001493号-1 )

版权所有 © 西安菁英教育科技有限公司 2023-2026