栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

pyside / pyqt:绑定具有相同功能的多个按钮的简单方法

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pyside / pyqt:绑定具有相同功能的多个按钮的简单方法

如果您有一个Buttons和LineEdits列表,则可以使用以下命令:

  • QSignalMapper
    ,另一个说明

  • functools.partial
    , 像这样:

    def show_dialog(self, line_edit):...line_edit.setText(...)

    for button, line_edit in zip(buttons, line_edits):
    button.clicked.connect(functools.partial(self.show_dialog, line_edit))

  • lambda

    for button, line_edit in ...: button.clicked.connect(lambda : self.show_dialog(line_edit))

如果您使用的是Qt Designer,并且没有按钮和lineedit的列表,但是它们都具有相同的命名模式,则可以使用一些自省:

class Foo(object):    def __init__(self):        self.edit1 = 1        self.edit2 = 2        self.edit3 = 3        self.button1 = 1        self.button2 = 2        self.button3 = 3    def find_attributes(self, name_start):        return [value for name, value in sorted(self.__dict__.items())    if name.startswith(name_start)]foo = Foo()print foo.find_attributes('edit')print foo.find_attributes('button')


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/611458.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号