- 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
Creating Clickable Tkinter labels
Tkinter Label widgets provide a way to display text and images in the Tkinter application window. We can configure the properties of the label widget by defining the attributes and properties in it. The Label widget can be converted into a clickable object by defining a function that contains some operation which can later be bound with a key.
Example
In this example, we will create a Label widget. Clicking over the Label widget will redirect the user to a specified webpage. So, the label will act as a hyperlink.
#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=('Helvetica', 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 window containing a Label widget. Clicking over the label will redirect the user to the website "www.tutorialspoint.com"
- Related Articles
- How do you create a clickable Tkinter Label?
- Creating Tkinter full-screen application
- Creating a Dropdown Menu using Tkinter
- Creating a Browse Button with Tkinter
- Creating an automatically maximized tkinter window
- Creating a button in tkinter in Python
- Creating a Frameless window in Python Tkinter
- Creating a Transparent window in Python Tkinter
- Creating a prompt dialog box using Tkinter?
- Creating a LabelFrame inside a Tkinter Canvas
- Creating scrollable Listbox within a grid using Tkinter
- Creating a table look-a-like using Tkinter
- Creating a graph with date and time in axis labels with Matplotlib
- Creating a tkinter GUI layout using frames and grid
- How to dynamically add/remove/update labels in a Tkinter window?

Advertisements