PyQt5 QSpinbox – Accessing the line edit object of it
Last Updated :
17 May, 2020
In this article we will see how we can access the line edit object of the spin box, line edit is widget in PyQt5 which is used to display text and accept the input text. By default spin box has its own line edit object although we can add our own line edit object to it with the help of setLineEdit
method.
In order to do this we use lineEdit method
Syntax : spin_box.lineEdit()
Argument : It takes no argument
Return: It returns line edit object
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" )
line = self .spin.lineEdit()
label = QLabel( self )
label.setText( str (line))
label.adjustSize()
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...