How to pass arguments to callback functions in PyQt

后端 未结 5 1501
臣服心动
臣服心动 2020-11-30 10:21

I have around 10 QAction (this number will vary in runtime) in a toolbar, which all will do same thing, but using different parameters. I am thinking to add parameter as an

5条回答
  •  执笔经年
    2020-11-30 11:17

    How to pass arguments to callback functions in PyQt

    You can use functools.partial from standart Python library. Example with QAction:

    some_action.triggered.connect(functools.partial(some_callback, param1, param2))
    

提交回复
热议问题