clear() method in PyQt5
Last Updated :
29 Dec, 2022
While using PyQt5, there occur a need of removing or clearing labels in order to do so clear() method is used. This method belongs to the QLabel class, and can be used on only label widgets.
Syntax : label.clear() Argument : It takes no argument. Action Performed : It clears(remove) the label from main window.
Below is the implementation of this method. Code :
Python3
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle("Move")
self .setGeometry( 0 , 0 , 500 , 300 )
self .label1 = QLabel( 'Label 1' , self )
self .label1.move( 100 , 100 )
self .label2 = QLabel( 'Label 2 ' , self )
self .label2.move( 100 , 120 )
self .label2.clear()
self .label3 = QLabel( 'Label 3' , self )
self .label3.move( 100 , 140 )
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output : As in the above image we can see Label2 will not be seen because of clear() method.
Share your thoughts in the comments
Please Login to comment...