- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 do you create a clickable Tkinter Label?
Label widgets in Tkinter are used to display text and images. We can link a URL with the label widget to make it clickable. Whenever the label widget is clicked, it will open the attached link in the default browser.
To work with the browser and hyperlinks we can use webbrowser module in Python. The module is accessible in Python extension library and can be installed by typing the command pip install webbrowser in the shell.
In this application, we will create a Label which turns out to be a Hyperlink referring to a webpage.
# Import the required library from tkinter import * import webbrowser # Create an instance of tkinter frame win = Tk() win.geometry("700x350") def open_url(url): webbrowser.open_new_tab(url) # Create a Label Widget label= Label(win, text= "Welcome to TutorialsPoint", cursor= "hand2", foreground= "green", font= ('Aerial 18')) label.pack(pady= 30) # Define the URL to open url= 'https://www.tutorialspoint.com/' # Bind the label with the URL to open in a new tab label.bind("<Button-1>", lambda e:open_url(url)) win.mainloop()
Upon clicking the label, the user will be redirected to the homepage of Tutorialspoint.
- Related Articles
- How do you create a Button on a Tkinter Canvas?
- How to create a hyperlink with a Label in Tkinter?
- Creating Clickable Tkinter labels
- How do you create a Tkinter GUI stop button to break an infinite loop?
- Python Tkinter – How do I change the text size in a label widget?
- How do I create a popup window using Tkinter?
- How do I create a popup window in Tkinter?
- How do I create a date picker in tkinter?
- How to update a Python/tkinter label widget?
- How do I create a popup window using Tkinter Program?
- How to create clickable links in a textView on Android?
- How do you create a list in Java?
- How do you check if a widget has a focus in Tkinter?
- How do you overlap widgets/frames in Python tkinter?
- Deleting a Label in Python Tkinter