Skip to content

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.

@FedericoSpada
Copy link
Collaborator

Hi,
you changed way too much, proposing to improve the coding style, but you have implemented it just for 1 widget, breaking the consistency.

Finally, I would avoid adding a new dedicated parameter to solve this specific and quite unusual case: we can reuse the same "anchor" parameter and provide it to the tkinter.Label().

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.

2 participants