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 :

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!