Python How to Create SpinBox in Pyside2

In this Python article we are going to talk about How to Create SpinBox in Pyside2, the QSpinBox  class provides a spin box widget, 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. the spin box supports integer values but can be extended to use different strings with validate(), textFromValue() and valueFromText().  every time the value changes QSpinBox emits valueChanged() and textChanged() signals, the former providing a int and the latter a QString. The textChanged() signal provides the value with both prefix() and suffix() . The current value can be fetched with value() and set with setValue() .

 

 

Also you can check my previous articles on Pyside2 GUI Development.

 

1: Getting Started With Pyside2 | Qt For Python 

2: Pyside2 GUI Creating First Window 

3: Pyside2 GUI Creating Window Icon

4: Pyside2 GUI How To Create Icon Modes

5: Pyside2 GUI How To Create Tooltip

6: Pyside2 GUI QPushButton With Signal And Slot

7: Pyside2 GUI Making Center The Window 

8: Python GUI How To Create AboutBox

9: Python GUI How to Create Digital Clock in Pyside2

10: How To Create StatusBar In Pyside2 

11: Pyside2 Creating QProgressBar

12: Pyside2 Layout Managment with QHBoxLayout

13: Pyside2 GridLayout Example

14: Pyside2 Creating Calendar 

15: Pyside2 Create CheckBox

16: Pyside2 Creating FontComboBox

17: Pyside2 Creating QCompleter 

18: Pyside2 GUI Creating Slider 

19: Pyside2 Create MenuBar & MenuItems

20: Pyside2 Creating TextEdit 

21: Pyside2 Creating Print Preview Dialog

22: How to Create Print Dialog in Pyside2

23: Python Exporting File as PDF with Pyside2

24: Pyside2 How to Create ColorDialog

25: How to Create ColorDialog in Pyside2

 

 

 

 

 

So now this is the complete source code for this article

 

 

 

 

OK now in here we are going to set our window title, also we need to set the geometry of the window, like x and y position of the window, also width and height of the window .

 

 

 

 

Also in this method we have created our method for setting window icon.

 

 

 

In here we have created the object of QDoubleSpinBox, and also we have set the minimum and maximum value for the spinbox , you can see that at the bottom of the code we have connected the valueChanged signal of QSpinBox with the spin_value() method that we have created.

 

 

 

And this is the method that we have already connected this at the top.

 

 

 

Because we are using QVBoxLayout, now we need to add our widgets in the QVBoxLayout.

 

 

 

Finally, we have  entered to the mainloop of the application. The event handling starts from this point. also we have created the object of our window in this class.

 

 

 

 

So run the complete code this will be the result

Python How to Create SpinBox in Pyside2
Python How to Create SpinBox in Pyside2

 

 

 

 

 

 

Also you can watch the complete video for this article

 

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×