How to align checkbutton in ttk to the left side?

To align checkbuttons to the left side in tkinter, you can use the anchor parameter and set it to "w" (west). This ensures that the text and checkbox are positioned to the left within their allocated space.

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.

  • Create checkbuttons inside the LabelFrame and set their anchor to "w" (west).

  • Use the width parameter to provide adequate space for left alignment.

  • Finally, run the mainloop of the application window.

Example

Here's a complete example showing how to left-align checkbuttons ?

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 with left alignment
C1 = Checkbutton(frame, text="Mathematics", width=20, anchor="w")
C1.pack(fill="x", pady=2)

C2 = Checkbutton(frame, text="Physics", width=20, anchor="w")
C2.pack(fill="x", pady=2)

C3 = Checkbutton(frame, text="Chemistry", width=20, anchor="w")
C3.pack(fill="x", pady=2)

C4 = Checkbutton(frame, text="Biology", width=20, anchor="w")
C4.pack(fill="x", pady=2)

root.mainloop()

Output

Running this code will create a window with left-aligned checkbuttons ?

tkinter Window Select the Subjects Mathematics Physics Chemistry Biology

Key Points

  • The anchor="w" parameter aligns content to the west (left) side.

  • Setting an appropriate width value provides space for the alignment to be visible.

  • Using fill="x" in the pack method helps distribute the checkbuttons evenly.

  • The pady parameter adds vertical spacing between checkbuttons for better appearance.

Conclusion

Use anchor="w" to left-align checkbuttons in tkinter. Combine it with appropriate width and packing options for optimal visual alignment and spacing.

Updated on: 2026-03-26T18:33:59+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements