Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I center justify a ttk::button's label ???

1,433 views
Skip to first unread message

JHJL

unread,
Apr 20, 2010, 7:32:42 AM4/20/10
to
Hi all

I really cannot fathom how to simply make a ttk::button's label center
jusitfied. I have tried looking at ttk::style man page and determined
that there is a Button.label element which does have a -justify
option, how on earth do I set it?

Any ideas greatfully received

kind regards
Julian H J Loaring

JHJL

unread,
Apr 20, 2010, 7:35:19 AM4/20/10
to

forgot to say that the button labels have two lines

eg .b configure -text "first line\nsecond line"

by default ttk left aligns the label which (to me) looks ugly

Georgios Petasis

unread,
Apr 20, 2010, 8:42:41 AM4/20/10
to JHJL

I think that you need to create a new style:


ttk::style configure My.TButton -justify center
ttk::button .b -style My.TButton -text "first line\nsecond line"

I think one of the best tutorials about ttk is here:

http://www.tkdocs.com/tutorial/

Chapter 15.

George

JHJL

unread,
Apr 20, 2010, 10:24:57 AM4/20/10
to
On Apr 20, 1:42 pm, Georgios Petasis <peta...@iit.demokritos.gr>
wrote:
> George- Hide quoted text -
>
> - Show quoted text -

Many thanks for Georgios, that works.

Alas I am still mystified as to how setting -justify on the style gets
propogated down to configure the Button.label element! Even after
reading the tutorial :-)

kind regards
Julian

Georgios Petasis

unread,
Apr 20, 2010, 11:19:46 AM4/20/10
to

When you change an option on a style, this option changes in all
elements that support this option, skipping elements that do not support
the option.

So, when you discovered that the label element has a -justify (or a
-anchor) option, the way to change it is through the style command.

So, if you change the TButton style, it will affect all buttons (since
the TButton is the default button style). A better way to do it, is
through creating a new style. Naming the new style "Anything".TButton,
means "inherit" everything from TButton, so My.TButton has all the
properties from TButton, but with different -justify option for all
elements that support it.

George

JHJL

unread,
Apr 21, 2010, 2:54:23 PM4/21/10
to
On Apr 20, 4:19 pm, Georgios Petasis <peta...@iit.demokritos.gr>

And then all became clear. Thank you so much for your time and
consideration Georgios.

kind regards
Julian

0 new messages