三个按钮,button_1,button_2,button_3
想点击哪个显示哪个,为什么我这一直都是输出button 1
环境:Windows 10, python 3.7.9
from PyQt5 import QtWidgets
class Program(QtWidgets.QWidget):
def __init__(self):
super(Program, self).__init__()
layout = QtWidgets.QVBoxLayout(self)
for n in range(3):
new_b = QtWidgets.QPushButton(self)
new_b.setText('button {}'.format(n+1))
new_b.clicked.connect(lambda n=n: print('button {}'.format(n+1)))
layout.addWidget(new_b)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
window = Program()
window.show()
sys.exit(app.exec_())
--
修改:lambdago FROM 119.103.17.*
FROM 119.103.17.*