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 −

Updated on: 26-Oct-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements