Key functions: Qpushbutton's Setobjectname ()/objectname ()
Personal Note: Press the function or area to bind the button's click event to a different slot function.
From pyqt5.qtwidgets import (Qapplication, Qwidget, Qpushbutton, Qhboxlayout, qlineedit) from Pyqt5.qtgui import *< C1/>from Pyqt5.qtcore Import * import sys def clickhandle (): # #main代表按钮的容器widget的对象 button = Main.sender () print (Button.objectname ()) If __name__ = = ' __main__ ': app=qapplication (SYS.ARGV) main= Qwidget () latout = Qhboxlayout () main.setlayout (latout) but_1 = Qpushbutton (' but_1 ') but_1. Setobjectname (' but_1 ') but_1.clicked.connect (clickhandle) but_2 = Qpushbutton (' but_2 ') but_2. Setobjectname (' but_2 ') but_2.clicked.connect (clickhandle) edit_1 = Qlineedit () edit_2 = Qlineedit () latout.addwidget (but_1) latout.addwidget (but_2) latout.addwidget (edit_1) Latout.addwidget (edit_2) Main.show () app.exec_ ()
PYQT the slot function of the Multiple-button click event to send the signal button.