PyQt5 – Get opacity level of the main window | windowOpacity() method
Last Updated :
26 Mar, 2020
windowOpacity()
method allows us to see the opacity level of the main window. Opacity is the measure of impenetrability to electromagnetic or other kinds of radiation, especially visible light. In radiative transfer, it describes the absorption and scattering of radiation in a medium, such as a plasma, dielectric, shielding material, glass, etc.
Opacity level ranges from 0.0 to 1.0, where 0.0 means completely transparent and 1.0 means completely opaque, by default it is 1.0 i.e completely opaque.
Syntax : self.windowOpacity()
Argument : It takes no argument.
Return : Returns a float value ranging from 0.0 to 1.0
Example 1:
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 .setGeometry( 60 , 60 , 600 , 400 )
level = str ( self .windowOpacity())
self .label_1 = QLabel(level, self )
self .label_1.move( 100 , 100 )
self .label_1.setStyleSheet( "border :3px solid blue;" )
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Example 2:
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 .setGeometry( 60 , 60 , 600 , 400 )
self .setWindowOpacity( 0.7 )
level = str ( self .windowOpacity())
self .label_1 = QLabel(level, self )
self .label_1.move( 100 , 100 )
self .label_1.setStyleSheet( "border :3px solid blue;" )
self .show()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Share your thoughts in the comments
Please Login to comment...