• 技术文章 >Python技术 >Python基础教程

    python PyQt添加菜单选项

    小妮浅浅小妮浅浅2021-10-10 09:19:26原创2636

    1、QWidget提供.addActions().该方法采用一系列操作,并将其附加到当前的小部件对象中。

    2、参数action表示QAction将添加到给定的QWidget对象中。

    使用变体.addAction(),您可以提前创建您的操作,然后根据需要添加到您的菜单中。

    变体的签名:

    QWidget.addAction(action)

    实例

    class Window(QMainWindow):
        # Snip...
        def _createMenuBar(self):
            menuBar = self.menuBar()
            # File menu
            fileMenu = QMenu("&File", self)
            menuBar.addMenu(fileMenu)
            fileMenu.addAction(self.newAction)
            fileMenu.addAction(self.openAction)
            fileMenu.addAction(self.saveAction)
            fileMenu.addAction(self.exitAction)
            # Edit menu
            editMenu = menuBar.addMenu("&Edit")
            editMenu.addAction(self.copyAction)
            editMenu.addAction(self.pasteAction)
            editMenu.addAction(self.cutAction)
            # Help menu
            helpMenu = menuBar.addMenu(QIcon(":help-content.svg"), "&Help")
            helpMenu.addAction(self.helpContentAction)
            helpMenu.addAction(self.aboutAction)

    以上就是python PyQt添加菜单选项的方法,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python pyqt
    品易云
    上一篇:python PyQt如何使用资源 下一篇:python PyQt子菜单的使用

    相关文章推荐

    • python读取文件出现空行的解决• python pip安装第三方模块的介绍• python重写__new__ 方法• python单例的使用详解• python如何实现初始化执行一次• python中ConfigParser是什么• python rabbitmq是什么• python线程安全的两种情况• python线程通信Condition提供的方法• python正则表达式问号的使用• python选择排序算法的特点• python format()的格式化使用• python中%如何实现格式化• python中PyQt创建菜单栏• python PyQt如何使用资源

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网