Skip to content
Related Articles

Related Articles

Improve Article

PyQt5 – How to create semi transparent window ?

  • Last Updated : 26 Mar, 2020

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 :






# 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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :