当前位置: 首页 > 图灵资讯 > 行业资讯> python PyQt用动作填充工具栏

python PyQt用动作填充工具栏

发布时间:2024-06-26 21:26:32

1、在工具栏中添加选项或按钮,需要调用.addAction()。

2、调用.addAction()作为参数,允许在菜单和工具栏之间共享操作。

当你创建工具栏时,你通常会面临决定添加哪些选项的问题。通常,您只想在工具栏中添加最常用的操作。

实例

classWindow(QMainWindow):
#Snip...
def_createActions(self):
#Fileactions
self.newAction=QAction(self)
self.newAction.setText("&New")
self.newAction.setIcon(QIcon(":file-new.svg"))
self.openAction=QAction(QIcon(":file-open.svg"),"&Open...",self)
self.saveAction=QAction(QIcon(":file-save.svg"),"&Save",self)
self.exitAction=QAction("&Exit",self)
#Editactions
self.copyAction=QAction(QIcon(":edit-copy.svg"),"&Copy",self)
self.pasteAction=QAction(QIcon(":edit-paste.svg"),"&Paste",self)
self.cutAction=QAction(QIcon(":edit-cut.svg"),"C&ut",self)
#Snip...

以上是python PyQt用动作填充工具栏的方法,希望对大家有所帮助。更多Python学习指导:python基础教程

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

相关文章

如何让vim支持python3

如何让vim支持python3

2025-09-12
python2.7和3.6区别有哪些

python2.7和3.6区别有哪些

2025-09-12
python3有serial库吗

python3有serial库吗

2025-09-12
python中w、r表示什么意思

python中w、r表示什么意思

2025-09-12
python中如何把list变成字符串

python中如何把list变成字符串

2025-09-12
python命名空间是什么

python命名空间是什么

2025-09-12