In this article we will see how we can set value to the spin box. By default its value is 0 although user can change it any time. In order to change its value programmatically we will use setValue
method
Syntax : spin.setValue(n)
Argument : It takes integer as argument
Return : None
Below is the implementation
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
self .spin = QSpinBox( self )
self .spin.setGeometry( 100 , 100 , 100 , 40 )
self .spin.setValue( 20 )
App = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(App. exec ())
|
Output :
