PyQt5 Push Button

Push button widget QPushButton is a command button in PyQt5. It is clicked by the user to command the PC to perform some specific action, like Apply, Cancel and Save.

Push Button - QPushButton

QPushButton.py
import sys
from PyQt5 import QtWidgets

def basicWindow():
    app = QtWidgets.QApplication(sys.argv)
    windowExample = QtWidgets.QWidget()
    
    buttonA = QtWidgets.QPushButton(windowExample)
    labelA = QtWidgets.QLabel(windowExample)
    
    buttonA.setText('Click!')
    labelA.setText('Show Label')
    
    windowExample.setWindowTitle('Push Button Example')
    
    buttonA.move(100, 50)
    labelA.move(110, 100)
    
    windowExample.setGeometry(100, 100, 300, 200)
    windowExample.show()
    sys.exit(app.exec_())

basicWindow()

Where,

buttonA = QtWidgets.QPushButton(windowExample)

buttonA is the QPushButton from QtWidgets and it should be added to the window windowExample the same as labels introduced in last chapters.

buttonA.setText('Click!')

It sets the text of buttonA to be Click!.

PyQt5 Push Button

It’s actually not going to do anything。