如何在tkinter python中的光标周围绘制定义的大小圆圈?
我尝试了
canvas.config(cursor='circle')
,但它绘制了一个特定的圆圈,其大小无法更改。
您可以在tkinter中使用 Motion
绑定,这会导致函数每次移动鼠标时激活:
import tkinter as tk
global circle
circle = 0
def motion(event):
x, y = event.x + 3, event.y + 7
#the addition is just to center the oval around the center of the mouse
#remove the the +3 and +7 if you want to center it around the point of the mouse
global circle
global canvas
canvas.delete(circle) #to refresh the circle each motion
radius = 20 #change this for the size of your circle
x_max = x + radius
x_min = x - radius
y_max = y + radius
y_min = y - radius
circle = canvas.create_oval(x_max, y_max, x_min, y_min, outline="black")
root = tk.Tk()
root.bind("<Motion>", motion)
global canvas
canvas = tk.Canvas(root)
canvas.pack()
root.mainloop()
我不建议通常使用全局变量,但是对于这样的简单程序,没关系。
您无法绘制自定义光标。您有一组非常有限的光标可供选择。