#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    12
    Rep Power
    0

    Hypelink with Tkinter


    How do i make a hyperlink with Tkinter? In html i do this: <a href="testing.htm">test</a>.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    well it is not really hard just use the httplib... to connect and to go to that site do a button
    Those people who think they know everything are a great annoyance to those of us who do.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    12
    Rep Power
    0
    But is it also possible to make a link in a large text? I don't want to use a button. Could someone give an example?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    12
    well you could use a label widget and a event system and test if the mouse was over the label when you clicked
    Those people who think they know everything are a great annoyance to those of us who do.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Hi!

    Here is a clever script from Fredrik Lundh which might help you

    Regards, mawe
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2005
    Posts
    12
    Rep Power
    0
    Thanks a lot! It works!

    But how to open the hyperlink in my browser?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Originally Posted by datbenik
    But how to open the hyperlink in my browser?
    Hmm, good question. Here is one way (there must be a better one ):
    Python Code:
    import webbrowser
    ...
     
    def callback(url):
        webbrowser.open(url)
     
    root = Tk()
    text = Text()
    text.pack()
    hyperlink = HyperlinkManager(text)
    text.insert(INSERT, 
        "this is a link",
        hyperlink.add(lambda:callback("http://www.the_url.com")))


    Regards, mawe
  14. #8
  15. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    After you've contained the sting that holds the value of the URL you would like to visit, you can do:
    Code:
    import os
    os.startfile('http://www.google.com') # or whatever the URL is
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    os.startfile()? Strange, my os module doesn't have this method.
  18. #10
  19. A wanna-be guru of some sort
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2004
    Location
    Either online or offline
    Posts
    625
    Rep Power
    20
    You can also do something like:
    Python Code:
    import webbrowser
    webbrowser.open('www.google.com')
    Am I supposed to sign here?
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    394
    Rep Power
    52
    Originally Posted by Boki
    You can also do something like:
    Originally Posted by mawe (2 posts before)
    import webbrowser
    ...

    def callback(url):
    webbrowser.open(url)
  22. #12
  23. A wanna-be guru of some sort
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2004
    Location
    Either online or offline
    Posts
    625
    Rep Power
    20
    Originally Posted by mawe
    Ooops, I wasn't looking carefully.
    Am I supposed to sign here?

IMN logo majestic logo threadwatch logo seochat tools logo