9

I am re designing a portion of my current software project, and want to use hyperlinks instead of Buttons. I really didn't want to use a Text widget, but that is all I could find when I googled the subject. Anyway, I found an example of this, but keep getting this error:

TclError: bitmap "blue" not defined

When I add this line of code (using the IDLE)

hyperlink = tkHyperlinkManager.HyperlinkManager(text)

The code for the module is located here and the code for the script is located here

Anyone have any ideas?

The part that is giving problems says foreground="blue", which is known as a color in Tkinter, isn't it?

4
  • "giving problems"? like a traceback, perhaps? what is it? Commented Aug 4, 2010 at 2:25
  • This is the exact error is here <br><br> It seems to think that "blue" is a bitmap. Commented Aug 4, 2010 at 2:28
  • This may be slightly irrelevant since you're on Windows. But I tried this on Ubuntu Linux, Python 2.6, and it works without any sort of errors. Maybe it's your installation / config problems? Commented Aug 4, 2010 at 3:06
  • I don't get the "blue" error when I use the code linked to in the question, though I'm running this on a Mac. Commented Aug 4, 2010 at 11:11

2 Answers 2

13

If you don't want to use a text widget, you don't need to. An alternative is to use a label and bind mouse clicks to it. Even though it's a label it still responds to events.

For example:

import tkinter as tk

class App:
    def __init__(self, root):
        self.root = root
        for text in ("link1", "link2", "link3"):
            link = tk.Label(text=text, foreground="#0000ff")
            link.bind("<1>", lambda event, text=text: self.click_link(event, text))
            link.pack()

    def click_link(self, event, text):
        print("You clicked '%s'" % text)

root = tk.Tk()
app = App(root)
root.mainloop()

If you want, you can get fancy and add additional bindings for <Enter> and <Leave> events so you can alter the look when the user hovers. And, of course, you can change the font so that the text is underlined if you so choose.

Tk is a wonderful toolkit that gives you the building blocks to do just about whatever you want. You just need to look at the widgets not as a set of pre-made walls and doors but more like a pile of lumbar, bricks and mortar.

Sign up to request clarification or add additional context in comments.

Comments

1

"blue" should indeed be acceptable (since you're on Windows, Tkinter should use its built-in color names table -- it might be a system misconfiguration on X11, but not on Windows); therefore, this is a puzzling problem (maybe a Tkinter misconfig...?). What happen if you use foreground="#00F" instead, for example? This doesn't explain the problem but might let you work around it, at least...

4 Comments

@Zachary, you mean you're giving #00F and it's still complaining about a "blue" that doesn't exist any more??? Or isn't that what you mean by "the exact same error"?
Probably because it isn't looking for a color at all but a bitmap "blue" not defined as you state first.
Yes, it is still complaining about "blue", which doesn't exist any more.
Ok, but where is it looking for the bitmap? I went through all the code, but can't find anything that says it is a bitmap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.