How to display multiple labels in one line with Python Tkinter?


To display multiple labels in one line with Python Tkinter, we can use the pack() method of label and align all the labels to the same side. Let's take an example and see how to display multiple labels in one line.

Steps −

  • Import the required libraries and create an instance of tkinter frame.

  • Set the size of the frame using geometry method.

  • Create a label and name it "Label 1". Set its font and highlight the label with a background color.

  • Next, use the pack() method of label and set side=LEFT to force the label to position itself on the left of the screen.

  • Similarly, create two more labels, "Label 2" and "Label 3" with different background colors and same pack parameters.

  • Finally, run the mainloop of the application window.

Example

from tkinter import *

win = Tk()
win.title("Labels in One Line")
win.geometry("700x350")

label1=Label(win, text="Label 1", font=("Times",30,"bold"), bg='red')
label1.pack(side=LEFT, pady=15)

label2=Label(win, text="Label 2", font=("Times",30,"bold"), bg='blue')
label2.pack(side=LEFT, pady=15)

label3=Label(win, text="Label 3", font=("Times",30,"bold"), bg='green')
label3.pack(side=LEFT, pady=15)

win.mainloop()

Output

On execution, it will produce the following output with all the three labels placed in one line −

Updated on: 26-Oct-2021

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements