cursorlocation

admin 560 0

以下是一个使用cursorlocation关键字的简单编程案例,该案例使用Python语言编写:

```python

import tkinter as tk

def show_cursor_location(event):

# 获取鼠标当前位置的坐标

x = event.x

y = event.y

# 在窗口标题栏上显示鼠标位置的坐标

root.title(f"鼠标位置:({x}, {y})")

root = tk.Tk()

root.title("鼠标位置示例")

# 创建一个标签组件,用于显示鼠标位置

label = tk.Label(root, text="鼠标位置:")

label.pack()

# 绑定鼠标移动事件,调用show_cursor_location函数来更新鼠标位置

root.bind("", show_cursor_location)

root.mainloop()

```