How to Create Label Using Tkinter?

  • Python
  • 3 mins read

In this tutorial, you will learn how to create a label using the Tkinter library in Python. Examples are given to create a label on a window, in a Frame object on a window and the dynamic Label.

Create a Label Using Tkinter Example

In the following example, it will create a label on the window object using Label() method. To check for more examples on how to create a window using Tkinter, you can see the following article How to Create a window using Tkinter in Python.

from tkinter import *

window = Tk()

window.title("Main Window")
window.configure(width=500, height=300)
window.geometry("500x300")

label1 = Label(window, text="Tkinter APP")
label1.pack()

window.mainloop()

Output

Create a label using Tkinter example

To increase the font size of the label, specify the font parameter in the Label method as shown below:

label1 = Label(window, text="Tkinter APP", font="arial, 22")
label1.pack()

In the below example, it will display the label in the top left corner using the grid() command instead of pack().

from tkinter import *

window = Tk()

window.title("Main Window")
window.configure(width=500, height=300)
window.geometry("500x300")

label1 = Label(window, text="Tkinter APP", font="arial, 22")
label1.grid(row=0, column=0)

window.mainloop()

Create Multiple Labels on Specific Rows and Columns Using grid()

In the following example, it will create the multiple labels on specific rows and columns with different colors using the fg attribute of Label() method.

from tkinter import *

window = Tk()

window.title("Main Window")
window.configure(width=500, height=300)
window.geometry("500x300")

label1 = Label(window, text="First Label", fg="red")
label1.grid(row=0, column=0)
label2 = Label(window, text="Label Next to the First Label", fg="blue")
label2.grid(row=0, column=1)

label3 = Label(window, text="New Label", fg="black")
label3.grid(row=2, column=0)

window.mainloop()

OutputCreate the labels with different colors in Tkinter

Create Labels Inside Frames on The Window Object

In the following example, it will create the Frames object first and then will add the label inside the frames. You can use the frames to organize positions on the window.

from tkinter import *

window = Tk()

window.title("Main Window")
window.configure(width=500, height=300)
window.geometry("500x300")
frame1 = Frame(window)
frame1.pack(side="top")
frame2 = Frame(window)
frame2.pack(side="bottom")

label1 = Label(frame1, text="Top Label", font="arial, 12")
label1.pack(side="left")
label3 = Label(frame1, text="Second Top Label", font="arial, 12")
label3.pack(side="left")

label2 = Label(frame2, text="Bottom Label", font="arial, 12")
label2.pack()

window.mainloop()

Output

Create a label inside the frame example using Tkinter

Tkinter Dynamic Label Example

Here is an example to create a label dynamically. The below function myapp takes an argument and will print on the window using the Label object.

from tkinter import *

def myapp(textLabel):
    window = Tk()

    window.title("Main Window")
    window.configure(width=500, height=300)
    window.geometry("500x300")

    vartext = textLabel
    label1 = Label(window, text="Hello", font="arial, 12")
    label1.grid(row=0, column=0)
    label2 = Label(window, text=vartext, font="arial, 12")
    label2.grid(row=0, column=1)
    window.mainloop()

myapp("Vinish")

Output

Tkinter create dynamic label example.