如何在tkinter python中的光标周围绘制一个定义的大小圆?在tkinter python中的光标周围绘制一个定义的大小圆
我试图
canvas.config(cursor='circle')
,但它吸引一个特定的圆,其大小不能改变。
如何在tkinter python中的光标周围绘制一个定义的大小圆?在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()
我不建议使用全局变量一般,但对于这样一个简单的程序, 没关系。
你问的是如何绘制一个圆圈(在画布上?),还是你问如何获得包含指针和圆圈的光标? –
我需要在移动光标时得到一个圆形的圆圈(与上面的代码相同,但能够更改大小),而不仅仅是绘制一个圆。 – Oleksandr