Align text in tkinter Button

Question:

By default text in Button is centered but I want it to be aligned to the left so when I type more text than the button can display it wont cut the start of the sentence/word. Thanks for help.

Asked By: Martin Pavelka

||

Answers:

You can use anchor="w" when defining the button. However, some platforms may ignore that. For example, on older version of OSX the text will always be centered.

Answered By: Bryan Oakley

I used this to justify the text in my buttons to the left. I have multiple buttons with different text lengths. They’re easier to read if the text starts at the same position

root = tkinter.Tk(className=' AutocompleteEntry demo')

frm = tkinter.ttk.Frame(root, padding=5)

style: tkinter.ttk.Style = tkinter.ttk.Style()

# Justify to the left [('Button.label', {'sticky': 'w'})]
style.layout("TButton", [('Button.button', {'sticky': 'nswe', 'children': [('Button.focus', {'sticky': 'nswe', 'children': [('Button.padding', {'sticky': 'nswe', 'children': [('Button.label',
    {'sticky': 'w'})]})]})]})])

frm.grid()

tkinter.ttk.Button(frm, text='check_if_email_in_estimating',
                   command=check_if_email_in_estimating).grid(column=0, sticky='we')

#
#
tkinter.ttk.Button(frm, text='shorter text',
               command=lambda: create_blank_billing_email(combo.get())).grid(column=0, sticky='we')
root.mainloop()
#
stylename_elements_options('TButton')
Answered By: JSotelo
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.