PyQt5 – How to create semi transparent window ?
When we design an application in PyQt5, the main window is used to appear by default the window is opaque, but we can make it transparent as well. we can do this by using setWindowOpacity()
method which belongs to the QWidget class
.
Syntax : setWindowOpacity(0.5)
Argument : It takes float value as argument : 0 for completely transparent and 1 for opaque.
Action performed : Makes the window transparent.
Code :
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle( "Python" )
self .setWindowOpacity( 0.5 )
self .setGeometry( 60 , 60 , 600 , 400 )
self .label_1 = QLabel( "transparent " , self )
self .label_1.move( 100 , 100 )
self .label_1.adjustSize()
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Last Updated :
26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...