![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 align checkbutton in ttk to the left side?
To align the checkbuttons to left, you can use the anchor parameter and set it to "w" (west). Let's take an example and see how to do it.
Steps −
Import the tkinter library and create an instance of tkinter frame.
Set the size of the frame using geometry method.
Create a LabelFrame to collect the checkbuttons in a group.
Next, create a checkbutton inside the LabelFrame and set its anchor to the West. anchor='w'.
Similarly, create three more checkbuttons with their anchor set at West. It will align all the checkbuttons to the left.
Finally, run the mainloop of the application window.
Example
from tkinter import * root = Tk() root.geometry("700x350") # Create a LabelFrame frame = LabelFrame(root, text="Select the Subjects", padx=20, pady=20) frame.pack(pady=20, padx=10) # Create four checkbuttons inside the frame C1 = Checkbutton(frame, text="Mathematics", width=200, anchor="w").pack() C2 = Checkbutton(frame, text = "Physics", width=200, anchor="w").pack() C3 = Checkbutton(frame, text = "Chemistry", width=200, anchor="w").pack() C4 = Checkbutton(frame, text = "Biology", width=200, anchor="w").pack() root.mainloop()
Output
On execution, it will produce the following output −
Advertisements