ubuntu20.04 pyqt5设置透明窗口显示黑色
时间: 2023-07-31 17:06:07 浏览: 68
你可以尝试使用以下代码来设置透明窗口并显示黑色背景:
```python
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
class TransparentWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setStyleSheet("background-color: black;")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = TransparentWindow()
window.show()
sys.exit(app.exec())
```
这段代码创建了一个继承自 QWidget 的 TransparentWindow 类,其中设置了窗口的标志为 `Qt.FramelessWindowHint`,这将使窗口没有标题栏和边框。然后,通过 `setAttribute(Qt.WA_TranslucentBackground)` 设置了窗口的背景透明。最后,通过 `setStyleSheet("background-color: black;")` 将窗口的背景颜色设置为黑色。
你可以将上述代码保存为一个 Python 文件,并在 Ubuntu 20.04 上运行。这将打开一个黑色的透明窗口。