How to create a label in a GUI with Python

Second post about tkinter from zero. We have seen how to make a button, now we take a look at labels. It’s easy as you may know, we will also check how o bind the click of the mouse to the label to make a call to a function that does change the text of the label. Enjoy the video.

import tkinter as tk

def click(event):
	lab["text"]="touched"


root = tk.Tk()
root.geometry("400x400")
root.title("Label")
lab = tk.Label(
	root,
	text="My label",
	font="Arial 20",
	fg="red",
	bg="yellow")
lab.pack()
lab.bind(
	"<Button-1>", click)

root.mainloop()

In the previous post we’ve seen how to make a button with tkinter

How to create buttons is a GUI with Python and the module tkinter


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.