Open In App

PyQt5 - How to create semi transparent window ?

Last Updated : 26 Mar, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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 : Python3 1==
# importing the required libraries

from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys


class Window(QMainWindow):


    def __init__(self):
        super().__init__()


        # set the title
        self.setWindowTitle("Python")

        self.setWindowOpacity(0.5)


        # setting  the geometry of window
        self.setGeometry(60, 60, 600, 400)

        # creating a label widget
        self.label_1 = QLabel("transparent ", self)
        # moving position
        self.label_1.move(100, 100)

        self.label_1.adjustSize()

        # show all the widgets
        self.show()


# create pyqt5 app
App = QApplication(sys.argv)

# create the instance of our Window
window = Window()

# start the app
sys.exit(App.exec())
Output : pyqt-semitranparent-window

Next Article
Article Tags :
Practice Tags :

Similar Reads