Buttons (QPushButton) can be added to any window. The QPushButton class has the method setText() for its label and move(x,y) for the position.
In this article you can see how a button can be added to a window, and how you can connect methods to it.
Related Course: Create GUI Apps with Python PyQt5
PyQt Button Example
Signals and slots
You can create a button with a few lines of code:
1 | button1 = QPushButton(widget) |
Then connect it to a method with:
1 | button1.clicked.connect(button1_clicked) |
The receiving method is called a slot, the clicked.connect (if the button is clicked) is called a signal.
1 | def button1_clicked(): |
Button example
Run the code below to see 2 buttons in a window. You can click either one of the buttons and their connected methods will be called.
1 | import sys |
If you are new to Python PyQt, then I highly recommend this book.