在Tkinter中改变鼠标指针
Tkinter是一个基于GUI的Python库,用于开发各种类型的功能性和GUI-based的应用程序。它提供了很多函数和方法,可以在开发应用程序时提供可扩展性和各种特性。
在本文中,我们将看到如何使用鼠标指针在Tkinter框架中的按钮上悬停时更改鼠标指针。在Tkinter的按钮库中有很多鼠标指针映射,为最终用户提供不同的可视化效果。库中一些鼠标指针如下,
“arrow”
“circle”
“clock”
“cross”
“dotbox”
“exchange”
“fleur”
“heart”
“heart”
“man”
“mouse”
“pirate”
“plus”
“shuttle”
“sizing”
“spider”
“spraycan”
“star”
“target”
“tcross”
“trek”
“watch”
首先让我们创建一些按钮,然后我们将在鼠标指针上应用其中一些指针。
示例
from tkinter import *
#创建窗口或框架的实例
win= Tk()
#设置几何
win.geometry("700x600")
win.resizable(0,0)
win.config(cursor= "fleur")
#让我们创建一个文本标签
Label(win, text= "在这些按钮上悬停鼠标", font=('Poppins', 20)).pack(pady=20)
#创建一些带有光标属性的按钮
b1= Button(win, text= "星星",cursor="star")
b1.pack(pady=20)
b2= Button(win, text= "箭头",cursor="arrow")
b2.pack(pady=20)
b3= Button(win, text= "圆圈",cursor="circle")
b3.pack(pady=20)
b4= Button(win, text= "时钟",cursor="clock")
b4.pack(pady=20)
b5= Button(win, text= "心形",cursor="heart")
b5.pack(pady=20)
b6= Button(win, text= "人物",cursor="man")
b6.pack(pady=20)
b7= Button(win, text= "鼠标",cursor="mouse")
b7.pack(pady=20)
#持续运行窗口
win.mainloop()
输出
运行上述代码将创建具有不同鼠标指针形状的不同按钮。