使用Sender()函数
// An highlighted block
class MyWindow(QWidget):
def __init__(self):
super(MyWindow, self).__init__()
self.setui()
# ============================================= #
def calculate(self):
button = self.sender()
print("button:{}".format(button.text()))
def setui(self):
data = [
["7","8","9","+"],
["4","5","6","-"],
["1","2","3","*"],
["0",".","=","/"]
]
for row_num,row_data in enumerate(data):
for col_num,col_data in enumerate(row_data):
button = QPushButton(col_data)
button.clicked.connect((self.calculate))
grid_layout.addWidget(button,row_num,col_num)