PyQt5 – Set border to the Push button
In this article we will see how to add border to Push Button. Although push button already have a border but that border is default. PyQt5 allows us to change the border of push button by using setStyleSheet
method.
Below is the example of push button with default border and customized border.
Syntax : button.setStyleSheet(“border :3px solid green”)
Argument : It takes string as argument
Action performed : It changes the border of the button
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 , 100 , 40 )
button.setStyleSheet( "border :3px solid green" )
button.clicked.connect( self .clickme)
def clickme( self ):
print ( "pressed" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Last Updated :
22 Apr, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...