Skip to content

Commit 7ee90bd

Browse files
committed
Address comments for PR #80, LinkLabel
1 parent e8c3e0d commit 7ee90bd

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

tests/test_linklabel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def test_linklabel_config(self):
3636
self.window.update()
3737
label["clicked_color"] = "purple"
3838
self.window.update()
39+
label.config(cursor="hand1")
40+
self.window.update()
41+
self.assertEquals(str(label.cget("cursor")), "hand1")
3942

4043
def test_linklabel_cget(self):
4144
label = LinkLabel(self.window, link="www.google.com", text="Visit Google")

ttkwidgets/linklabel.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Edited 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
1010
import tkinter as tk
1111
from tkinter import ttk
1212
import 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

Comments
 (0)