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.
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.
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')
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.
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.
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')