diff --git a/README.md b/README.md index 0da18b1..f138acc 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,10 @@ - [1.17 下拉选择联动](下拉选择联动/) - [1.18 人脸描点检测](人脸描点检测/) - [1.19 腾讯视频热播列表](腾讯视频热播列表/) - - [1.20 exec()动态生成控件](partner_625781186/1.exec动态生成控件/) + - 1.20 exec()动态生成控件 + - [1. 动态控件基础例子 - 动态生成按钮](partner_625781186/1.exec动态生成控件/dynamic_button) + - [2. 动态控件基础例子 - 动态生成菜单](partner_625781186/1.exec动态生成控件/dynamic_Menu) + - [3. 配合setting记录模型类型](partner_625781186/1.exec动态生成控件/) - [1.21 仿QQ设置面板](仿QQ设置面板/) - [1.22 Json生成QTreeWidget](Json生成QTreeWidget/) - [1.23 嵌入外部窗口](嵌入外部窗口/) diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/Ui_345円212円250円346円200円201円346円216円247円344円273円266円.py" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/Ui_345円212円250円346円200円201円346円216円247円344円273円266円.py" new file mode 100644 index 0000000..bfefe94 --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/Ui_345円212円250円346円200円201円346円216円247円344円273円266円.py" @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'D:\pyPro\dynamic_Menu\动态控件.ui' +# +# Created by: PyQt5 UI code generator 5.9.2 +# +# WARNING! All changes made in this file will be lost! + +from PyQt5 import QtCore, QtGui, QtWidgets + +class Ui_Dialog(object): + def setupUi(self, Dialog): + Dialog.setObjectName("Dialog") + Dialog.resize(370, 403) + Dialog.setSizeGripEnabled(True) + self.verticalLayout = QtWidgets.QVBoxLayout(Dialog) + self.verticalLayout.setObjectName("verticalLayout") + + self.retranslateUi(Dialog) + QtCore.QMetaObject.connectSlotsByName(Dialog) + + def retranslateUi(self, Dialog): + _translate = QtCore.QCoreApplication.translate + Dialog.setWindowTitle(_translate("Dialog", "Dialog")) + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + Dialog = QtWidgets.QDialog() + ui = Ui_Dialog() + ui.setupUi(Dialog) + Dialog.show() + sys.exit(app.exec_()) + diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/__init__.py" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/__init__.py" new file mode 100644 index 0000000..e69de29 diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/dynamic_Controls.e4p" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/dynamic_Controls.e4p" new file mode 100644 index 0000000..e66480e --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/dynamic_Controls.e4p" @@ -0,0 +1,47 @@ + + + + + + + en_US + b35a15d37a7cb52779310396c238b2e70ac76888 + Python3 + PyQt5 + 0.1 + + + + + Ui_动态控件.py + __init__.py + 动态控件.py + + +
动态控件.ui
+
+
+ + + + + None + + + + + + + + + + + + + + + + + + + diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/345円212円250円346円200円201円346円216円247円344円273円266円.py" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/345円212円250円346円200円201円346円216円247円344円273円266円.py" new file mode 100644 index 0000000..53a5c84 --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/345円212円250円346円200円201円346円216円247円344円273円266円.py" @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- + +""" +Module implementing Dialog. +""" + +from PyQt5 import QtGui, QtWidgets, QtCore, QtWinExtras +from PyQt5.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * + +from functools import partial +from Ui_动态控件 import Ui_Dialog + +class Dialog(QDialog, Ui_Dialog): + + def __init__(self, parent=None): + + super(Dialog, self).__init__(parent) + self.setupUi(self) + + self.dynamic1() + + self.dynamic2() + +# 法一 + def dynamic1(self): + for i in range(5): + self.pushButton = QtWidgets.QPushButton(self) + self.pushButton.setText("pushButton%d"%i) + self.pushButton.setObjectName("pushButton%d"%i) + self.verticalLayout.addWidget(self.pushButton) + self.pushButton.setContextMenuPolicy(Qt.CustomContextMenu) + self.pushButton.customContextMenuRequested.connect(lambda:self.helpMenu(i))#右键请求,传入i实际上一直是4 + self.pushButton.clicked.connect(self.pr) + +# 法二 + def dynamic2(self): + for i in range(5, 8): + txt=""" +self.pushButton_{i} = QtWidgets.QPushButton(self); +self.pushButton_{i}.setText("pushButton{i}"); +self.pushButton_{i}.setObjectName("pushButton{i}"); +self.verticalLayout.addWidget(self.pushButton_{i}); + +self.pushButton_{i}.setContextMenuPolicy(Qt.CustomContextMenu) +self.pushButton_{i}.customContextMenuRequested.connect(partial(self.helpMenu,i))#右键请求,用lambda会报错,partial需要import + +self.pushButton_{i}.clicked.connect(self.pr) + """.format(i=i) + exec(txt) + #只能法二可用的方式 + self.pushButton_5.clicked.connect(self.pr2) + self.pushButton_6.clicked.connect(self.pr2) + self.pushButton_7.clicked.connect(self.pr2) + + + def helpMenu(self, *type): + '''帮助按钮的右键菜单''' + print(type) + popMenu =QMenu() + + if type[0]==5 or self.sender().text()== 'pushButton0': + popMenu.addAction(u'关于',self.pr) + popMenu.addSeparator() + + elif type[0]==6 or self.sender().text()== 'pushButton1': + popMenu.addAction(u'清理图片',self.pr) + popMenu.addSeparator() + + elif type[0]==7 or self.sender().text()== 'pushButton2': + gitMenu=QMenu('同步到Git', popMenu) + + self.pushAction=QAction(u'上传', self, triggered=lambda:self.pr) + gitMenu.addAction(self.pushAction) + + self.pullAction=QAction(u'下载', self, triggered=lambda:self.pr) + gitMenu.addAction(self.pullAction) + + gitMenu.addSeparator() + gitMenu.addAction(u'配置仓库',lambda:self.pr) + + popMenu.addAction(gitMenu.menuAction())#!! + popMenu.exec_(QCursor.pos())#鼠标位置 + + def pr(self): + '''法一和法二都可用的调用 + if self.sender().objectName=='XXX': + self.pr2() + ''' + print(self.sender().text()) + print(self.sender().objectName()) + print(self.pushButton.text()) + + def pr2(self): + print(2) + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + ui = Dialog() + ui.show() + sys.exit(app.exec_()) diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/345円212円250円346円200円201円346円216円247円344円273円266円.ui" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/345円212円250円346円200円201円346円216円247円344円273円266円.ui" new file mode 100644 index 0000000..66eecaa --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_Menu/345円212円250円346円200円201円346円216円247円344円273円266円.ui" @@ -0,0 +1,23 @@ + + + Dialog + + + + 0 + 0 + 370 + 403 + + + + Dialog + + + true + + + + + + diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/Ui_345円212円250円346円200円201円346円216円247円344円273円266円.py" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/Ui_345円212円250円346円200円201円346円216円247円344円273円266円.py" new file mode 100644 index 0000000..e5461d0 --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/Ui_345円212円250円346円200円201円346円216円247円344円273円266円.py" @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'D:\pyPro\dynamic_button\动态控件.ui' +# +# Created by: PyQt5 UI code generator 5.9.2 +# +# WARNING! All changes made in this file will be lost! + +from PyQt5 import QtCore, QtGui, QtWidgets + +class Ui_Dialog(object): + def setupUi(self, Dialog): + Dialog.setObjectName("Dialog") + Dialog.resize(370, 403) + Dialog.setSizeGripEnabled(True) + self.verticalLayout = QtWidgets.QVBoxLayout(Dialog) + self.verticalLayout.setObjectName("verticalLayout") + + self.retranslateUi(Dialog) + QtCore.QMetaObject.connectSlotsByName(Dialog) + + def retranslateUi(self, Dialog): + _translate = QtCore.QCoreApplication.translate + Dialog.setWindowTitle(_translate("Dialog", "Dialog")) + + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + Dialog = QtWidgets.QDialog() + ui = Ui_Dialog() + ui.setupUi(Dialog) + Dialog.show() + sys.exit(app.exec_()) + diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/__init__.py" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/__init__.py" new file mode 100644 index 0000000..e69de29 diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/dynamic_Controls.e4p" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/dynamic_Controls.e4p" new file mode 100644 index 0000000..e66480e --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/dynamic_Controls.e4p" @@ -0,0 +1,47 @@ + + + + + + + en_US + b35a15d37a7cb52779310396c238b2e70ac76888 + Python3 + PyQt5 + 0.1 + + + + + Ui_动态控件.py + __init__.py + 动态控件.py + + +
动态控件.ui
+
+
+ + + + + None + + + + + + + + + + + + + + + + + + + diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/345円212円250円346円200円201円346円216円247円344円273円266円.py" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/345円212円250円346円200円201円346円216円247円344円273円266円.py" new file mode 100644 index 0000000..178a61a --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/345円212円250円346円200円201円346円216円247円344円273円266円.py" @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- + +""" +Module implementing Dialog. +""" + +from PyQt5 import QtGui, QtWidgets, QtCore, QtWinExtras +from PyQt5.QtCore import * +from PyQt5.QtGui import * +from PyQt5.QtWidgets import * + +from Ui_动态控件 import Ui_Dialog + + +class Dialog(QDialog, Ui_Dialog): + + def __init__(self, parent=None): + + super(Dialog, self).__init__(parent) + self.setupUi(self) + self.dynamic1() + self.dynamic2() + +# 法一 + def dynamic1(self): + for i in range(5): + self.pushButton = QtWidgets.QPushButton(self) + self.pushButton.setText("pushButton%d"%i) + self.pushButton.setObjectName("pushButton%d"%i) + self.verticalLayout.addWidget(self.pushButton) + self.pushButton.clicked.connect(self.pr) +# 法二 + def dynamic2(self): + for i in range(4): + txt=""" +self.pushButton_{i} = QtWidgets.QPushButton(self); +self.pushButton_{i}.setText("pushButton{i}"); +self.pushButton_{i}.setObjectName("pushButton{i}"); +self.verticalLayout.addWidget(self.pushButton_{i}); +self.pushButton_{i}.clicked.connect(self.pr) + """.format(i=i) + exec(txt) + #只能法二可用的方式 + self.pushButton_1.clicked.connect(self.pr2) + self.pushButton_2.clicked.connect(self.pr2) + self.pushButton_3.clicked.connect(self.pr2) + + def pr(self): + '''法一和法二都可用的调用 + if self.sender().objectName=='XXX': + self.pr2() + ''' + print(self.sender().text()) + print(self.sender().objectName()) + print(self.pushButton.text()) + + def pr2(self): + print(2) + +if __name__ == "__main__": + import sys + app = QtWidgets.QApplication(sys.argv) + ui = Dialog() + ui.show() + sys.exit(app.exec_()) diff --git "a/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/345円212円250円346円200円201円346円216円247円344円273円266円.ui" "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/345円212円250円346円200円201円346円216円247円344円273円266円.ui" new file mode 100644 index 0000000..66eecaa --- /dev/null +++ "b/partner_625781186/1.exec345円212円250円346円200円201円347円224円237円346円210円220円346円216円247円344円273円266円/dynamic_button/345円212円250円346円200円201円346円216円247円344円273円266円.ui" @@ -0,0 +1,23 @@ + + + Dialog + + + + 0 + 0 + 370 + 403 + + + + Dialog + + + true + + + + + +

AltStyle によって変換されたページ (->オリジナル) /