[Python] 纯文本查看 复制代码import sys
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QPainter, QColor
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget
class FloatingWindow(QMainWindow):
def __init__(self):
super().__init__()
# 设置无边框和透明度
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
# 获取屏幕大小
screen = QApplication.primaryScreen()
screen_rect = screen.availableGeometry()
screen_width, screen_height = screen_rect.width(), screen_rect.height()
# 设置窗口大小为整个屏幕
self.setGeometry(0, 0, screen_width, screen_height)
# 定时器用于更新窗口内容
self.timer = QTimer(self)
self.timer.timeout.connect(self.update_content)
self.timer.start(100) # 每100毫秒更新一次内容
def update_content(self):
# 更新窗口内容(绘制网格)
self.update()
def paintEvent(self, event):
# 在窗口上绘制网格
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
grid_size = 20
grid_color = QColor(0, 0, 0, 150) # 透明黑色
# 绘制横向网格线
for y in range(0, self.height(), grid_size):
painter.drawLine(0, y, self.width(), y)
# 绘制纵向网格线
for x in range(0, self.width(), grid_size):
painter.drawLine(x, 0, x, self.height())
if __name__ == '__main__':
app = QApplication(sys.argv)
window = FloatingWindow()
window.show()
sys.exit(app.exec_())