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

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()

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 14:06:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 14:06:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 14:06:03       58 阅读
  4. Python语言-面向对象

    2024-07-12 14:06:03       69 阅读

热门阅读

  1. 【史上最全面ESP32教程】http通信

    2024-07-12 14:06:03       21 阅读
  2. C++ STL常用容器之vector(顺序容器)

    2024-07-12 14:06:03       21 阅读
  3. SQL注入:时间盲注

    2024-07-12 14:06:03       24 阅读
  4. Mybatis插件:IDEA中MyBatisCodeHelperPro插件下载安装

    2024-07-12 14:06:03       17 阅读
  5. spark中的floor函数

    2024-07-12 14:06:03       21 阅读
  6. 数据结构第21节 归并排序以及优化方案

    2024-07-12 14:06:03       21 阅读
  7. 手撕红黑树

    2024-07-12 14:06:03       20 阅读