新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:PythonPyQt菜單的動態(tài)填充
為了繼續(xù)開發(fā)示例應用程序,假設您需要在_文件_下創(chuàng)建_打開最近的_子菜單,并動態(tài)填寫最近打開的文件或文檔。因此,需要操作以下步驟:

創(chuàng)新互聯(lián)公司是專業(yè)的阜康網(wǎng)站建設公司,阜康接單;提供成都網(wǎng)站制作、網(wǎng)站設計,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行阜康網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
1、在_File_下創(chuàng)建_Open最近的_子菜單。
2、編寫動態(tài)生成操作,填寫菜單的定制插槽。
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)以上就是python PyQt菜單的動態(tài)填充的方法,希望對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
網(wǎng)站標題:創(chuàng)新互聯(lián)Python教程:PythonPyQt菜單的動態(tài)填充
網(wǎng)頁地址:http://m.fisionsoft.com.cn/article/dpoijeo.html


咨詢
建站咨詢
