多个按钮使用不同的参数调用相同的功能

时间:2019-07-18 14:34:23

标签: python

我想通过for循环创建多个按钮。 按下按钮可调用相同的功能,但传递不同的参数。我该怎么做? 示例:

def someFunction(self):
      for i in range(8):
            square_btn_1 = QPushButton(self)                               
            square_btn_1.clicked.connect(self.function(i))

def function(self, i):
       print(i)

但是它总是发送7

0 个答案:

没有答案