PyQt5 QSpinBox – Getting whole text
Last Updated :
17 May, 2020
In this article we will see how we can get the whole text of the spin box, whole text mean the value as well as prefix and suffix included.
In order to do so we use text
method.
Syntax : spin_box.text()
Argument : It takes no argument
Return : It returns string
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 , 250 , 40 )
self .spin.setPrefix( "Prefix " )
self .spin.setSuffix( " Suffix" )
text = self .spin.text()
print (text)
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Prefix 0 Suffix
Share your thoughts in the comments
Please Login to comment...