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

anchor=center attribute in button not working #7

Closed
zerozedsc opened this issue Nov 17, 2021 · 6 comments
Closed

anchor=center attribute in button not working #7

zerozedsc opened this issue Nov 17, 2021 · 6 comments

Comments

@zerozedsc
Copy link

I already use style to center the text in the button, but the text cant be aligned to the center, can I know how to do so with your theme? sorry for opening this issue

@RGerculy
Copy link

RGerculy commented Nov 18, 2021

Hi, your issue is very vague, can you add more details? Which layout manager are you using in your application? Maybe include some code as well.
This is working for me:
button1.place(relx=0.5, rely=0.5, anchor=CENTER)

@zerozedsc
Copy link
Author

I'm using pack layout, but when I'm using tk.Button the text-align well at the center. so maybe ttk.button does not align all text even after \n at the center.

This is my code:
button_1 = ttk.Button(self.left, text="ABCDEFGHIJKLMNOP\nQRSTUVWXYZ", width=int(W_LEFT/8), command=None, style=style1) button_1.pack(fill='x', anchor=CENTER, pady=1)

@RGerculy
Copy link

RGerculy commented Nov 18, 2021

Had to modify the code a little but I hope it still works for you.

        button_1 = ttk.Style()
        button_1.configure('Button1.TButton', justify='center')
        button_1 = ttk.Button(frame, text="ABCDEFGHIJKLMNOP\nQRSTUVWXYZ", width=8, command=None, style='Button1.TButton') 
        button_1.pack(fill='x', anchor=CENTER, pady=1)

button1

As far as anchor=center goes, I was unable to center it alone with that but hopefully this will help.

@zerozedsc
Copy link
Author

yes, it works now. thank you. but why when using anchor=CENTER nothing happen with ttk.button. when using it on tk.button, it works well

@RGerculy
Copy link

I noticed that as well when testing your code unfortunately that is beyond my abilities. Hopefully somebody else will be able to address that issue.

@zerozedsc
Copy link
Author

I noticed that as well when testing your code unfortunately that is beyond my abilities. Hopefully somebody else will be able to address that issue.

Okey, thank you for helping me. I think i will close this issue, because it is not a big issue at all

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

No branches or pull requests

2 participants