66Edited by rdbende: default, native cursors, virtual event, colors
77"""
88# Based on an idea by Nelson Brochado (https://www.github.com/nbrol/tkinter-kit)
9- # Unfortunately this link is invalid. I can't find any nbrol, or Nelson Brochado on GitHub :(
9+ # Available from fork: https://www.github.com/RedFantom/tkinter-kit
1010import tkinter as tk
1111from tkinter import ttk
1212import webbrowser
@@ -16,7 +16,7 @@ class LinkLabel(ttk.Label):
1616 """
1717 A :class:`ttk.Label` that can be clicked to open a link with a default blue color, a purple color when clicked and a bright
1818 blue color when hovering over the Label.
19- """
19+ """
2020 def __init__ (self , master = None , ** kwargs ):
2121 """
2222 Create a LinkLabel.
@@ -30,20 +30,21 @@ def __init__(self, master=None, **kwargs):
3030 :type hover_color: str
3131 :param clicked_color: text color when link is clicked
3232 :type clicked_color: str
33+ :param cursor: string name for cursor to display on hover
34+ :type cursor: str
3335 :param kwargs: options to be passed on to the :class:`ttk.Label` initializer
3436 """
3537 self ._link = kwargs .pop ("link" , "" )
3638 self ._normal_color = kwargs .pop ("normal_color" , "#005fff" )
3739 self ._hover_color = kwargs .pop ("hover_color" , "#000fff" )
3840 self ._clicked_color = kwargs .pop ("clicked_color" , "#6600a6" )
3941 self ._master = master or tk ._default_root
40- if self ._master .tk .call ("tk" , "windowingsystem" ) == "aqua" :
41- self ._cursor = kwargs .pop ("cursor" , "pointinghand" )
42- else :
43- self ._cursor = kwargs .pop ("cursor" , "hand2" )
42+ ismac = self ._master .tk .call ("tk" , "windowingsystem" ) == "aqua"
43+ if "cursor" not in kwargs :
44+ kwargs ["cursor" ] = "pointinghand" if ismac else "hand2"
4445 ttk .Label .__init__ (self , master , ** kwargs )
4546 if "disabled" not in self .state ():
46- self .configure (foreground = self ._normal_color , cursor = self . _cursor )
47+ self .configure (foreground = self ._normal_color )
4748 self .__clicked = False
4849 self .bind ("<Button-1>" , self .open_link )
4950 self .bind ("<Enter>" , self ._on_enter )
@@ -93,7 +94,6 @@ def configure(self, **kwargs):
9394 self ._hover_color = kwargs .pop ("hover_color" , self ._hover_color )
9495 self ._normal_color = kwargs .pop ("normal_color" , self ._normal_color )
9596 self ._clicked_color = kwargs .pop ("clicked_color" , self ._clicked_color )
96- self ._cursor = kwargs .pop ("cursor" , self ._cursor )
9797 ttk .Label .configure (self , ** kwargs )
9898
9999 config = configure
0 commit comments