How Do I Change My Cursor To A Hand Only When It Is Hovering Over A Label?
from tkinter import * root = Tk() def changeCursor(event, pointerName): root.cursor(pointerName) link = Label(root, text='Link') link.bind('', lambda event : chan
Solution 1:
If you want the cursor to always be the hand, just configure the label to have that cursor:
import tkinter as tkroot= tk.Tk()
label = tk.Label(root, text="Hello, world", background="bisque", cursor="hand1")
label.pack(side="top", fill="x", padx=10, pady=10)
root.mainloop()
Solution 2:
import tkinter as tkroot= tk.Tk()
myLabel= tk.Label(root, text="Click Me", cursor="hand2")
myLabel.pack()
root.mainloop()
Solution 3:
For a quick preview of the available cursors:
(taken from https://www.tcl.tk/man/tcl8.4/TkCmd/cursors.htm)
import tkinter as tk
root = tk.Tk()
frame = tk.Frame(root)
frame.pack(expand=True, fill=tk.BOTH)
cursors = """
X_cursor
arrow
based_arrow_down
based_arrow_up
boat
bogosity
bottom_left_corner
bottom_right_corner
bottom_side
bottom_tee
box_spiral
center_ptr
circle
clock
coffee_mug
cross
cross_reverse
crosshair
diamond_cross
dot
dotbox
double_arrow
draft_large
draft_small
draped_box
exchange
fleur
gobbler
gumby
hand1
hand2
heart
icon
iron_cross
left_ptr
left_side
left_tee
leftbutton
ll_angle
lr_angle
man
middlebutton
mouse
pencil
pirate
plus
question_arrow
right_ptr
right_side
right_tee
rightbutton
rtl_logo
sailboat
sb_down_arrow
sb_h_double_arrow
sb_left_arrow
sb_right_arrow
sb_up_arrow
sb_v_double_arrow
shuttle
sizing
spider
spraycan
star
target
tcross
top_left_arrow
top_left_corner
top_right_corner
top_side
top_tee
trek
ul_angle
umbrella
ur_angle
watch
xterm""".split()
i = 0
j = 0for cur in cursors:
if i == 20:
i = 0
j += 1
tk.Button(frame, text=cur, height=2, width=15, cursor=cur).grid(row=i, column=j)
i += 1
tk.mainloop()
Post a Comment for "How Do I Change My Cursor To A Hand Only When It Is Hovering Over A Label?"