PyQt comes with a slider, QSlider. You can use this slider to select a value. A slider can be a great input widget for volume.
It allows a user to quickly change the value on a widget range, in contrast to a numeric counter. The range of a QSlider is from 0 to 100, where 100 is 100%.
Related Course: Create GUI Apps with Python PyQt5
A slider can be horizontal or vertical. You can choose a type, when creating a slider. Either Qt.Horizontal or Qt.Vertical.
First import QSlider and Qt.
from PyQt5.QtCore import Qt
Then create a slider:
mySlider = QSlider(Qt.Horizontal, self)
Then set its geometry (position and size):
mySlider.setGeometry(30, 40, 200, 30)
And connect a method that’s called when changing its value:
The program below creates an empty window with a horizontal slider. If you want a vertical slider, don’t forget to change the geometry.
Copy and paste the code below to try a slider:
If you are new to Python PyQt, then I highly recommend this book.