PyQt5 | How to create capsule shaped push button ?
Last Updated :
22 Apr, 2020
Capsule shape is basically shape which consist of one rectangle and two semi circle is connected to both the ends, in this tutorial we will see how to create these shaped button.
Below is normal Push button vs capsule shaped push button.
In order to create capsule shape button we have to do the following steps :
1. Create a button.
2. Resize the button to make it rectangle.
3. Set the radius of button using style sheet to half of height.
Note : If the button will not be rectangle it will become circle.
Code :
from PyQt5.QtWidgets import *
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 ):
button = QPushButton( "CLICK" , self )
button.setGeometry( 200 , 150 , 150 , 40 )
button.clicked.connect( self .clickme)
button.setStyleSheet("border : 2px solid black;
border - radius : 20px ;")
def clickme( self ):
print ( "pressed" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Share your thoughts in the comments
Please Login to comment...