[Tkinter-discuss] newbie request for help
alexxxm
magni at inrim.it
Wed Jun 8 08:48:41 CEST 2011
ooops, I just found out:
the code for tkHyperlinkManager is at http://pastebin.com/mWfDm7eZ
alessandro
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alexxxm wrote:
>
> I thank you all for your help and I'm looking forward to implement it.
> At the moment however I'm unable to do it since it appears I'm missing a
> basic piece:
>
> trying to approach the links, at first I used the code found at
> http://effbot.org/zone/tkinter-text-hyperlink.htm:
> <code>
> import tkHyperlinkManager
> from Tkinter import *
>
> root = Tk()
> root.title("hyperlink-1")
>
> text = Text(root)
> text.pack()
>
> hyperlink = tkHyperlinkManager.HyperlinkManager(text)
>
> def click1():
> print "click 1"
>
> text.insert(INSERT, "this is a ")
> text.insert(INSERT, "link", hyperlink.add(click1))
> text.insert(INSERT, "\n\n")
>
> def click2():
> print "click 2"
>
> text.insert(INSERT, "this is another ")
> text.insert(INSERT, "link", hyperlink.add(click2))
> text.insert(INSERT, "\n\n")
>
> mainloop()
> </code>
>
>
> but I get this:
> ImportError: No module named tkHyperlinkManager
>
> I work on Linux Fedora13, and my Tkinter version is
> tkinter-2.6.4-27.fc13.x86_64
> Probably tkHyperlinkManager is not included by default in the Tkinter
> distribution?
>
>
> As approach #2 I tried this (courtesy of StackOverflow):
> <code>
> import Tkinter
>
> class App:
> def __init__(self, root):
> self.root = root
> for text in ("link1", "link2", "link3"):
> link = Tkinter.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=Tkinter.Tk()
> app = App(root)
> root.mainloop()
> </code>
>
> and this works. Do you recommend this approach?
>
> alessandro
>
>
>
> alexxxm wrote:
>>
>> Hi everybody,
>> I need some help to understand if tkinter is in fact the right tool to
>> use for me.
>>
>> I intend to write a very bare-bone wiki in python. It should be able to:
>>
>> 1) open a text file
>> 2) display the text file, with links in the form {{image.jpg}} replaced
>> by the image, and [[linkname|linkfile.txt]] replaced by linkname
>> 3) when clicking on linkname, save the current text file and open in its
>> place the file linkfile.txt
>>
>> really, I'm not interested in nothing more.
>>
>> Do you believe it can be easily accomplished with tkinter, or do I need
>> some more complicated widget?
>>
>> Thanks for any help...
>>
>>
>> alessandro
>>
>>
>
>
--
View this message in context: http://old.nabble.com/newbie-request-for-help-tp31791699p31798134.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
More information about the Tkinter-discuss
mailing list