How To Create QSpinBox In PyQt5

In this PyQt5 article iam going to show you How To Create QSpinBox In PyQt5. also iam going to show you how you can connect valueChanged Signal to PyQt5 Slot. The QSpinBox class provides a spin box widget.QSpinBox is designed to handle integers and discrete sets of values (e.g., month names); use QDoubleSpinBox for floating point values.



What is PyQt5 QSpinBox ?

PyQt5 QSpinBox is a widget that allows users to select a numerical value within a specified range by clicking arrow buttons or typing the value directly into the spin box. it is similar to  regular QLineEdit widget, but it has up and down arrow buttons to increment or decrement the value, and it also enforces a range of values that the user can select from.

QSpinBox is part of the QtWidgets module in PyQt5 and inherits from QAbstractSpinBox. It can be customized by setting the range of values it can display, the step size for the increment and decrement buttons, the displayed number of digits, and other properties.




Also you can read more Python GUI articles in the below links




First we need some imports.




Now we need to create our main Window class that extends from QWidget, in the class first we set our window icon, window title and window geometry.




In here we have created the object of QVBoxLayout with QSpinBox.




So now we have connected the valueChanged signal of QSpinBox with spin_changed() method.




And this is the method or slot that we have connected with valueChanged signal at the top.




Also every PyQt5 application must create an application object. 




Finally, we enter the mainloop of the application. The event handling starts from this point. 




Complete source code for How To Create QSpinBox In PyQt5





Run the complete code and this is the result

How To Create QSpinBox In PyQt5
How To Create QSpinBox In PyQt5





Also you can watch the complete video for this article

1 thought on “How To Create QSpinBox In PyQt5”

Leave a Comment

Share via
Copy link
Powered by Social Snap