- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create hyperlink in a Tkinter Text widget?
Tkinter Text widgets are generally used for accepting multiline user input in the given text field. For a particular text document, the content may contain hyperlinks too which is useful in case we want to redirect the user. You can create hyperlinks within the text widget by using HyperLinkManager snippet in Python.
The HyperLinkManager code snippet adds the hyperlink on the keyword within the text widget. You can download the HyperLinkManager Snippet from here−
https://github.com/codewithdev/Code-Snippets/blob/master/tkinter/tkHyperlinkManager.py/
Once the snippet has been downloaded, you can import it in the notebook by typing "from tkHyperLinkManager import HyperlinkManager"
Example
# Import the required libraries from tkinter import * from tkHyperLinkManager import HyperlinkManager import webbrowser from functools import partial # Create an instance of tkinter frame win = Tk() win.geometry("700x350") # Define a callback function def callback(url): webbrowser.open_new_tab(url) # Create a Label to display the link text = Text(win) text.insert(END,"Hey Folks, Welcome to ") text.pack() hyperlink= HyperlinkManager(text) text.insert(END, "TutorialsPoint",hyperlink.add(partial(webbrowser.open,"http://www.tutorialspoint.com"))) win.mainloop()
Output
Executing the above code snippet will display a window containing a text widget and a keyword with hyperlink.
Whenever we click the link, it will open the URL on a web browser.
- Related Articles
- How to highlight text in a tkinter Text widget?
- How to create a hyperlink with a Label in Tkinter?
- How to attach a Scrollbar to a Text widget in Tkinter?
- How to attach a vertical scrollbar in Tkinter text widget?
- How to erase everything from a Tkinter text widget?
- How do I center the text in a Tkinter Text widget?
- How to insert a temporary text in a tkinter Entry widget?
- Printing a list to a Tkinter Text widget
- How to set default text for a Tkinter Entry widget?
- How to clear the contents of a Tkinter Text widget?
- How to take input in a text widget and display the text in tkinter?
- Add advanced features to a tkinter Text widget
- Underline Text in Tkinter Label widget
- Python Tkinter – How to display a table editor in a text widget?
- How to get the current length of the Text in a Tkinter Text widget?
