- 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
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 −
- Related Articles
- How to bind multiple events with one "bind" in Tkinter?
- How to display multiple lines of text in Tkinter Label?
- How to input multiple values from user in one line in Python?
- How to catch multiple exceptions in one line (except block) in Python?
- How to plot a Bar Chart with multiple labels in Matplotlib?
- How to display all the MySQL tables in one line?
- How to display multiple images in one figure correctly in matplotlib?
- How to add multiple text labels from DataFrame columns in Python Plotly?
- How to concatenate multiple C++ strings on one line?
- How to display Y-axis labels with more decimal places in R?
- How to display X-axis labels with dash in base R plot?
- How to force Tkinter text widget to stay on one line?
- How to input multiple values from user in one line in C#?
- How to input multiple values from user in one line in Java?
- How to display a Listbox with columns using Tkinter?
