python 屏幕显示一个文本窗口,文本窗口显示在当前鼠标在的位置,该文字窗口跟随鼠标移动,并且始终保持最前面显示 ,可以根据文字的多少来自动调节窗口大小

avatar
作者
猴君
阅读量:0

python 屏幕显示一个文本窗口,我有一段文字需要显示,鼠标在那里,文本窗口就在哪里显示,该文字窗口需要跟随鼠标移动,并且始终保持最前面显示,可以根据文字的多少来自动调节窗口大小

仅仅使用tkinter

# -*- coding:utf-8 -*-      import tkinter as tk  def update_position(event):     # 获取窗口的宽度和高度     width = root.winfo_width()     height = root.winfo_height()      # 获取屏幕的宽度和高度     screen_width = root.winfo_screenwidth()     screen_height = root.winfo_screenheight()      # 计算窗口的新位置,确保不会超出屏幕边界     new_x = max(0, min(event.x_root - width // 2, screen_width - width))     new_y = max(0, min(event.y_root - height // 2, screen_height - height))      # 更新主窗口的位置以跟随鼠标     root.geometry(f'+{new_x}+{new_y}')   def adjust_window_size():     # 获取标签所需的宽度和高度     label_width = text_label.winfo_reqwidth()

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!