Reputation: 59
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.
Upvotes: 4
Views: 15511
Reputation: 19
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')
Upvotes: 0
Reputation: 385970
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.
Upvotes: 11