• Centering text in button

    From Olivier@[email protected] to comp.lang.tcl on Mon Oct 5 14:17:00 2026
    From Newsgroup: comp.lang.tcl


    This is question from Harald that landed in a different thread,
    so I post here again :

    ------------------ Q start ------------------

    Buttons with multiple text lines:

    pack [button .b2 -justify center -text ABC\nD]

    may use the -justify option to center the lines.

    Now ttk:
    pack [ttk::button .b2 -justify center -text ABC\nD]
    no option justify

    ttk::style configure custom.Toolbutton -anchor center -justify center
    pack [ttk::button .b -style custom.Toolbutton -text centered\n2]

    no effect.

    Is there a way to center the text?

    This is Style Vista on MS-Windows...

    Thanks for any idea,
    Harald

    --------------- Q end -----------------

    What I saw is that styling works to center text in version 8.6 but not
    in 9.0. In 9.1 we have "Eliminate the "xpnative" ttk style, in favor of "vista"",.
    but cannot test it.
    It seems even magic that -anchor center -justify center association works
    in version 8.6 when the layout is only :

    Button.button -sticky nswe -children {Button.focus -sticky nswe
    -children {Button.padding -sticky nswe -children {Button.label -sticky nswe}}}

    I take advantage of Harald's question to know if it exists somewhere a description
    of how layout for each widget is described ? There are excellent theme such as clearlooks , ttkbootstrap or rdbende's themes that I keep wondering how they could be
    be built with this lack of information.

    Olivier.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Olivier@[email protected] to comp.lang.tcl on Mon Oct 5 15:34:55 2026
    From Newsgroup: comp.lang.tcl


    Olivier <[email protected]d> posted:



    pack [button .b2 -justify center -text ABC\nD]

    ....

    Is there a way to center the text?

    This is Style Vista on MS-Windows...

    Thanks for any idea,
    Harald


    In thread "Why I'm reverting from Tcl/Tk 9.1.0 to Tcl/Tk 9.0.3", it was noted :

    "There are other blocking known bugs in 9.1.0 like the non-functioning "-justify" in ttk widgets."

    This is probably the reason why centering text does not work.
    --- Synchronet 3.22a-Linux NewsLink 1.2