Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Justify text of a button #2173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

P3rdigas
Copy link

@P3rdigas P3rdigas commented Dec 29, 2023

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant