|
发表于 2024-3-18 22:23:05
|
显示全部楼层
最外层那个display,其实也不是不能透明:
- import sys
- from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel
- from PyQt5.QtGui import QPixmap, QPalette
- from PyQt5.QtCore import Qt
-
- class TransparentWindow(QMainWindow):
- def __init__(self):
- super().__init__()
- self.setWindowFlags(Qt.FramelessWindowHint) # 无边框
- self.setAttribute(Qt.WA_TranslucentBackground) # 背景透明
- self.initUI()
-
- def initUI(self):
- label = QLabel(self)
- label.setPixmap(QPixmap("your_image.png")) # 替换为你的图片路径
- label.setScaledContents(True)
- self.setCentralWidget(label)
-
- self.setGeometry(100, 100, 800, 600) # 窗口位置和大小
- self.show()
-
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- window = TransparentWindow()
- sys.exit(app.exec_())
复制代码 |
|