导语:
本文主要介绍了关于Python PyQt菜单的动态填充的相关知识,包括pyqt按钮调用python程序,以及word快捷菜单的填充在哪这些编程知识,希望对大家有参考作用。
要继续开发示例应用程序,假设你需要在 _File_ 下创建一个 _Open Recent_ 子菜单,并用最近打开的文件或文档动态填充它。因此,需要以下步骤:
1、在_File_下创建_Open最近的_子菜单。
2、编写动态生成操作,填写菜单的定制插槽。
3、连接.aboutToShow()菜单信号和自定义插槽。
实例
from functools import partial
# Snip...
class Window(QMainWindow):
# Snip...
def populateOpenRecent(self):
# Step 1. Remove the old options from the menu
self.openRecentMenu.clear()
# Step 2. Dynamically create the actions
actions = []
filenames = [f"File-{n}" for n in range(5)]
for filename in filenames:
action = QAction(filename, self)
action.triggered.connect(partial(self.openRecentFile, filename))
actions.append(action)
# Step 3. Add the actions to the menu
self.openRecentMenu.addActions(actions)
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 如何在大学里学好python11/04
- ♥ python函数有返回值吗?09/23
- ♥ python中解析XML中模块的方法有哪些01/03
- ♥ python搜索模块如何查询12/23
- ♥ 在 Python 中嵌套是什么?12/14
- ♥ 如何在 Python 中使用欧几里得求逆09/16
内容反馈