PyQt5 – 获取主窗口的不透明度级别| windowOpacity()方法

PyQt5 – 获取主窗口的不透明度级别| windowOpacity()方法

windowOpacity()方法可以让我们看到主窗口的不透明度水平。

不透明度 是衡量对电磁或其他种类的辐射,特别是可见光的不可渗透性。在辐射传输中,它描述了辐射在介质中的吸收和散射情况,如等离子体、电介质、屏蔽材料、玻璃等。

不透明度级别从0.0到1.0,其中0.0表示完全透明,1.0表示完全不透明,默认为1.0,即完全不透明。

语法: self.windowOpacity()

参数: 不需要参数。

返回: 返回一个从0.0到1.0的浮点数。

例子 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")
  
        # setting  the geometry of window
        self.setGeometry(60, 60, 600, 400)
  
        # getting opacity level
        level = str(self.windowOpacity())
  
        # creating a label widget
        self.label_1 = QLabel(level, self)
  
        # moving position
        self.label_1.move(100, 100)
  
        # setting up the border
        self.label_1.setStyleSheet("border :3px solid blue;")
  
        # 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())
Python

输出:

PyQt5 - 获取主窗口的不透明度级别 windowOpacity()方法

例2 :

# 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")
  
        # setting  the geometry of window
        self.setGeometry(60, 60, 600, 400)
  
        # setting opacity level
        self.setWindowOpacity(0.7)
  
        # getting opacity level
        level = str(self.windowOpacity())
  
        # creating a label widget
        self.label_1 = QLabel(level, self)
        # moving position
        self.label_1.move(100, 100)
  
        # setting up the border
        self.label_1.setStyleSheet("border :3px solid blue;")
  
        # 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())
Python

输出 :

PyQt5 - 获取主窗口的不透明度级别 windowOpacity()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册