- 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 a hyperlink with a Label in Tkinter?
Tkinter Label widgets are generally used to display text or images. In this example, we will see how to add a hyperlink on a Label widget in an application.
In order to add a hyperlink, we can bind the label text with a button that makes it clickable. The open_new(url) method is used to define the function that opens a web browser to follow the link. The open_new(url) method is defined in the webbrowser module in Python which can be imported in the notebook using 'import webbrowser'.
Example
#Import the required libraries from tkinter import * import webbrowser #Create an instance of tkinter frame win = Tk() win.geometry("750x250") #Define a callback function def callback(url): webbrowser.open_new_tab(url) #Create a Label to display the link link = Label(win, text="www.tutorialspoint.com",font=('Helveticabold', 15), fg="blue", cursor="hand2") link.pack() link.bind("<Button-1>", lambda e: callback("http://www.tutorialspoint.com")) win.mainloop()
Output
Running the above code will display a Label text with a URL.
The displayed window will show a hyperlink which upon clicking will redirect the user to the website: www.tutorialspoint.com
- Related Articles
- How to create hyperlink in a Tkinter Text widget?
- How do you create a clickable Tkinter Label?
- How to create a Hyperlink using JavaFX?
- How to update a Python/tkinter label widget?
- How to create a multiline entry with Tkinter?
- How to create a message box with Tkinter?
- How to create a hyperlink to link another document in HTML?
- Deleting a Label in Python Tkinter
- How to center a label in a frame of fixed size in Tkinter?
- How to add Label width in Tkinter?
- How to create a label using JavaFX?
- How to create a combo box with auto-completion in Tkinter?
- How to change the color of a Tkinter label programmatically?
- How to update the image of a Tkinter Label widget?
- How to change the size of text on a label in Tkinter?

Advertisements