PyQt5 QSpinBox – Accessing Suffix
Last Updated :
06 May, 2020
In this article we will see how we can access the suffix of the spin box, suffix is the extra text added at the end of the value, it is non editable and permanent. By default there is no suffix set to the spin box although we can set suffix any time with the help of setSuffix
method.
In order to do this we will use suffix
method.
Syntax : spin_box.suffix()
Argument : It takes no argument
Return : It returns string
Steps for implementation :
1. Create a spin box
2. Set suffix with the help of setSuffix method
3. Create label to show the suffix
4. Get the suffix with the help of suffix method
5. Show suffix through label
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 , 150 , 40 )
self .spin.setSuffix( " Number(s)" )
label = QLabel( self )
label.setGeometry( 100 , 160 , 200 , 30 )
suffix = self .spin.suffix()
label.setText( "Suffix: " + suffix)
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...