How to Create SpinBox with Python & PyQt

In this article we are going to learn How to Create SpinBox with Python & PyQt, QSpinBox is designed to handle integers and discrete sets of values QSpinBox allows the user to choose a value by clicking the up/down buttons or pressing up/down on the keyboard to increase/decrease the value currently displayed. The user can also type the value in manually. there are different method that you can use in QSpinBox for example we have value() and this method returns the current selected integer value in spinbox , we have setMinium() and setMaximum() methods, also there are some signals for QSpinBox, for example we have valueChanged() signal and it is emitted when the value of spinbox is changed also we have editingFinished() signal and it is emitted when the focus is lost on the spinbox.

 

 

 

 

 

This is the complete code for How to Create SpinBox with Python & PyQt

 

 

 

In here we have created the width and height also x and y position for the window.

 

This is used for adding title to the window.

 

 

 

In here we have created an icon, make sure that you have already added an icon to your working directory.

 

 

This is our label, for creating of the label you can use QLabel class.

 

 

In here we have created our QLineEdit.

 

 

Now we are going to create our spinbox in python & pyqt, for creating of spinbox we can use QSpinBox class.

 

 

As we have already said that there are different signals in QspinBox

that you can use, in here we are using toggled() signal of QSpinBox, we have

connected that with spin_selected method or slot.

 

 

 

This is the spin_selected() method, in this method we are getting the value

from QLineEdit and after that we multiply that with the spinbox value and

at the end we add the result in the totalResult label.

 

 

 

 

Run the complete code and this will be the result.

How to Create SpinBox with Python & PyQt
How to Create SpinBox with Python & PyQt
Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.

Leave a Comment