PyQt5 – How to create circle Label ?
When we create label, by default, they are rectangle in shape, we can use resize() method to change its width and height but still it will be quadrilateral. In this article, we will see how to create circular i.e round label. In order to do this we will first create a square label then with the help of setStyleSheet() method change its border radius to half of length of the label, which will look like this.
Syntax : label.setStyleSheet(border-radius: 40px;”) Argument : It takes string as argument. Action performed : Changes the border radius of label.
Code :
Python3
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5 import QtCore
from PyQt5.QtCore import Qt
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle(" round label")
self .setGeometry( 60 , 60 , 600 , 400 )
self .label_1 = QLabel( 'round label' , self )
self .label_1.move( 100 , 100 )
self .label_1.resize( 80 , 80 )
self .label_1.setStyleSheet("border: 3px solid blue;
border - radius: 40px ;")
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Last Updated :
03 Jan, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...