CustomTkinter
CustomTkinter copied to clipboard
Justify text of a button
After encounter an issue where the text of a button was bigger than the width of the button, the text seem justified to the center.
- Fixes issue #2171
An example:
import customtkinter
def show_value(selected_option):
print(selected_option)
APP_WIDTH = 200
APP_HEIGHT = 200
root = customtkinter.CTk()
root.geometry(f"{APP_WIDTH}x{APP_HEIGHT}")
root.resizable(width=False, height=False)
button1 = customtkinter.CTkButton(
root,
text="A LONG TEXT THAT IS LARGER THAN THE ORIGINAL",
width=30,
height=30,
anchor="w",
# text_anchor="w",
)
button1.pack(expand=False)
root.mainloop()
Resulting in:
After creating an new argument for the button, being text_anchor, and changing the _draw() function (adding the argument anchor with the value of the text_anchor variable) the following result can be obtained:
This modification solve this issue, however the argument border_spacing seems to not work with very long texts.