CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Justify text of a button

Open P3rdigas opened this issue 2 years ago • 0 comments

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: image

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: image

This modification solve this issue, however the argument border_spacing seems to not work with very long texts.

P3rdigas avatar Dec 29 '23 03:12 P3rdigas