PyQt5 supports buttons using the QPushButton class. This class is inside the PyQt5.QtWidgets group. The button can be created by calling the constructor QPushButton with the text to display as parameter.
Introduction To use buttons with a PyQt5 application, we need to update our import line:
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton from PyQt5.QtCore import pyqtSlot
In the initUI() method, add these lines of code:
button = QPushButton('PyQt5 button', self) button.setToolTip('This is an example button') button.move(100,70)
QPushButton creates the widget, the first argument is text on the button. The method setToolTip shows the message when the user points the mouse on the button. Finally the button is moved to the coordinates x=100,y=70. We need to create a method for a button click:
How to connect more than one function to single push button?
Frank•Tue, 12 Jan 2021
Buttons have one call back function. If you want to call multiple functions, you can do it inside the callback function. That means call another function inside the on_click function. You may be able to add another clicked.connect connect call, but I recmomend calling any functions you want to call in the on_click() function.
Leave a Reply:
How to connect more than one function to single push button?
Buttons have one call back function. If you want to call multiple functions, you can do it inside the callback function. That means call another function inside the on_click function. You may be able to add another clicked.connect connect call, but I recmomend calling any functions you want to call in the on_click() function.
Hi
Thanks for this example.
I have tried to create a test case to verify that the button wiring is working. With the help of a stackoverflow member this worked for me. May be worth to add a link?
https://stackoverflow.com/questions/67345474/extend-generated-testapp-to-verify-pyqt5-button-click
Regards, Jurg