Customtkinter checkboxes are not starting at the same x axis

Question:

I want to make a python todo app with customtkinter. When i create a checkbox which has a longer text everytime something goes wrong and for something they just go away.

Here is my code so far:

from customtkinter import *
from tkinter import *
import random

root = CTk()
root.geometry('400x600')
root.title('Todo')
root.resizable(False, False)
set_appearance_mode('light')
set_default_color_theme('blue')


#Main label
main_label = CTkLabel(root, text='Your To Do list', font=CTkFont(size=30, weight='bold'))
main_label.place(x=20, y=20)

#Under label
under_label_choices_list = [
    'This will be your best day',
    'Be productive',
    'Willpower',
]
under_label_choices = StringVar()
under_label_choices.set(random.choice(under_label_choices_list))

under_label = CTkLabel(root, textvariable=under_label_choices, text_color='#6495ED', font=CTkFont(size=15, weight='bold'))
under_label.place(x=20, y=50)

#Scrollableframe
scrollableframe = CTkScrollableFrame(root, width=300, height=400)
scrollableframe.place(x=40, y= 100)

#Add button
**def make_checkbox(event):
    global todo_entry
    checkbox = CTkCheckBox(scrollableframe, text=todo_entry.get(), font=CTkFont(size=15))
    todo_entry.destroy()
    checkbox.grid(padx=5, pady=5)


def add():
    global todo_entry
    todo_entry = CTkEntry(scrollableframe)
    todo_entry.bind('<Return>', make_checkbox)
    todo_entry.grid(padx=5, pady=5)
    todo_entry.focus()**


add_button = CTkButton(root, text='Add', command=add)
add_button.place(x=20, y=540)



root.mainloop()

I think the problem is in the bold part

Here is a picture too how it’s looks like

Asked By: Illes

||

Answers:

Try adding sticky='w' to the checkbox.grid() call, to make it align to the left side of the container.

Answered By: Ben the Coder

Try adding a width to the check box

def make_checkbox(event):
    global todo_entry
    checkbox = CTkCheckBox(scrollableframe, text=todo_entry.get(), font=CTkFont(size=15), width=200)
    todo_entry.destroy()
    checkbox.grid(padx=5, pady=5)

Now it should be fine.

Answered By: Rohan Menon