Discussion:
Grid Widgets same width and -sticky w
(too old to reply)
Alexandru
2023-08-14 09:42:53 UTC
Permalink
On https://www.magicsplat.com/tcl-docs/docindex.html there is an example how all buttons in a grid row can have same uniform width.

I would like that all button in the same column have same uniform width.

I could do that with -sticky ew but then the content of each button is centered.

Instead the content should be left aligned (-sticky e).

Is there a trick how to do this?

Thanks
Alexandru
Alexandru
2023-08-14 10:37:09 UTC
Permalink
Post by Alexandru
On https://www.magicsplat.com/tcl-docs/docindex.html there is an example how all buttons in a grid row can have same uniform width.
I would like that all button in the same column have same uniform width.
I could do that with -sticky ew but then the content of each button is centered.
Instead the content should be left aligned (-sticky e).
Is there a trick how to do this?
Thanks
Alexandru
Correction:
Instead the content should be left aligned (-sticky w).
Andreas Leitgeb
2023-08-14 11:27:12 UTC
Permalink
Post by Alexandru
Post by Alexandru
On https://www.magicsplat.com/tcl-docs/docindex.html there is an example how all buttons in a grid row can have same uniform width.
I would like that all button in the same column have same uniform width.
I could do that with -sticky ew but then the content of each button is centered.
Instead the content should be left aligned (-sticky e).
Is there a trick how to do this?
Instead the content should be left aligned (-sticky w).
Maybe you're looking for button's " -anchor w " ?
(for grid, you still need -sticky nsew or ew)
Alexandru
2023-08-14 20:04:09 UTC
Permalink
Post by Andreas Leitgeb
Post by Alexandru
Post by Alexandru
On https://www.magicsplat.com/tcl-docs/docindex.html there is an example how all buttons in a grid row can have same uniform width.
I would like that all button in the same column have same uniform width.
I could do that with -sticky ew but then the content of each button is centered.
Instead the content should be left aligned (-sticky e).
Is there a trick how to do this?
Instead the content should be left aligned (-sticky w).
Maybe you're looking for button's " -anchor w " ?
(for grid, you still need -sticky nsew or ew)
Yes! That's it. Here is a demo below.
All 3 buttons have same lenght and the text is left aligned.

ttk::button .b -style Toolbutton -text "Foo"
ttk::button .e -style Toolbutton -text "Foo Foo"
ttk::button .l -style Toolbutton -text "Foo Foo Foo"

grid .b -sticky ew
grid .e -sticky ew
grid .l -sticky ew

grid anchor .b w
grid anchor .e w
grid anchor .l w
Ralf Fassel
2023-08-15 08:53:04 UTC
Permalink
* Alexandru <***@meshparts.de>
| Andreas Leitgeb schrieb am Montag, 14. August 2023 um 13:27:17 UTC+2:
| > Alexandru <***@meshparts.de> wrote:
| > > Instead the content should be left aligned (-sticky w).
| > Maybe you're looking for button's " -anchor w " ?
| > (for grid, you still need -sticky nsew or ew)
| Yes! That's it. Here is a demo below.
| All 3 buttons have same lenght and the text is left aligned.
| ttk::button .b -style Toolbutton -text "Foo"
| ttk::button .e -style Toolbutton -text "Foo Foo"
| ttk::button .l -style Toolbutton -text "Foo Foo Foo"
| grid .b -sticky ew
| grid .e -sticky ew
| grid .l -sticky ew
| grid anchor .b w
| grid anchor .e w
| grid anchor .l w

I *think* that 'grid anchor' does something different than Andreas
suggested.

Andreas suggested to use the -anchor option of the ttk TButton style (he
posted for 'button', but since you're using a 'ttk::button', you need to
use the option with the same name of the ttk::style):

# only specific buttons should get anchor w, so create a separate style for it:
ttk::style configure W.TButton -anchor w

# use that style with the specific buttons
ttk::button .b -style Toolbutton -text "Foo" -style W.TButton
ttk::button .e -style Toolbutton -text "Foo Foo" -style W.TButton
ttk::button .l -style Toolbutton -text "Foo Foo Foo" -style W.TButton

grid .b -sticky ew
grid .e -sticky ew
grid .l -sticky ew

Compare the L&F of that to your code: on my system (Linux, tk8.6) with
your code the relief of the buttons is missing.

HTH
R'
Ralf Fassel
2023-08-15 08:56:15 UTC
Permalink
* Ralf Fassel <***@gmx.de>
| ttk::button .b -style Toolbutton -text "Foo" -style W.TButton

Ah, just spotted that you're using a separate Toolbutton style anyway,
so just do

ttk::style configure Toolbutton -anchor w

and you should be done with your code.

R'
Alexandru
2023-08-16 06:23:59 UTC
Permalink
| ttk::button .b -style Toolbutton -text "Foo" -style W.TButton
Ah, just spotted that you're using a separate Toolbutton style anyway,
so just do
ttk::style configure Toolbutton -anchor w
and you should be done with your code.
R'
Indeed, my code did work but only as it is. Ported in to the application, the result was nil.
With
ttk::style configure W.TButton -anchor w
I get the wanted result.

Many thanks for the help.

Loading...