• How do I know or configure the width of a grid column?

    From Luc@21:1/5 to All on Sun Oct 16 04:33:22 2022
    I am beginning to hate the grid geometry manager.

    Will you please take a look at this code?

    https://pastebin.com/iA8SLDMH

    I am beginning to hate the grid geometry manager because there are certain size/dimension options that we are supposed to be able to tweak, but when
    I tweak them, nothing happens. Grumble.

    Anyway, the real problem with the code is that there is a line with a label that says "Input:" followed by an entry widget. The distance that separates them is too great. I want the entry widget to be very close to the label.

    I find it very confusing because of this part of the code:

    grid $::w.outerframe
    grid $::w.outerframe.frame1_row1 -column 0 -row 0 -columnspan 10 -sticky n
    grid $::w.outerframe.frame2_row2 -column 0 -row 1 -columnspan 10 -sticky we
    grid $::w.outerframe.frame3A_row3_LEFT -column 0 -row 2 -columnspan 1 -sticky we
    grid $::w.outerframe.frame3B_row3_RIGHT -column 1 -row 2 -columnspan 9 -sticky we
    grid $::w.outerframe.frame4A_row4_LEFT -column 0 -row 3 -columnspan 1 -sticky we
    grid $::w.outerframe.frame4B_row4_RIGHT -column 1 -row 3 -columnspan 9 -sticky we
    grid $::w.outerframe.frame5_row5 -column 0 -row 4 -columnspan 10 -sticky s

    In my poor understanding, the second line (at least, among others)
    establishes that I want to treat the entire window like it has 10 columns.
    So I expect the "3A" frame (label) to occupy exactly 1/10 of the window's length, i.e. the "3B" frame (entry) to be exactly 1/10 of the window's length away from the leftmost wall. However, 3A seems to occupy about 20% of the window's length no matter what I do.

    Note that 3B is supposed to be 90% of the window's length. If I reduce it
    to 8 (80%), it shortens, but won't affect the width of 3A. If I set it to
    20 (200%), for example, it doesn't look any different. Either way, 3A won't budge. It keeps taking up 20% of the window's width.

    In my mind, we should be able to establish very clearly how many rows and columns the window is supposed to have, like adding a table to a Word
    document:

    grid $::w numberofcolumns 10
    grid $::w numberofrows 5

    All of which would be distributed in equal slices so the area and "borders"
    of each cell would be very easy to determine. Why not even this:

    grid $::w showgrid 1

    Such command would display a grid over the window like they do in photo
    editing applications to help you apply the Rule of Thirds. Which can be
    removed later when you're happy with all the widget placement.

    But I digress.

    How can I bring that entry widget closer to the label widget, please?

    TIA

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Sun Oct 16 14:43:52 2022
    Luc <[email protected]> wrote:
    I am beginning to hate the grid geometry manager.

    It is much easier to use to achieve most typicaly GUI layouts than
    pack.

    Will you please take a look at this code?

    https://pastebin.com/iA8SLDMH

    I am beginning to hate the grid geometry manager because there are certain size/dimension options that we are supposed to be able to tweak, but when
    I tweak them, nothing happens. Grumble.

    Because some of them only 'function' when other settings are toggled
    on.

    I find it very confusing because of this part of the code:

    grid $::w.outerframe
    grid $::w.outerframe.frame1_row1 -column 0 -row 0 -columnspan 10 -sticky n
    grid $::w.outerframe.frame2_row2 -column 0 -row 1 -columnspan 10 -sticky we
    grid $::w.outerframe.frame3A_row3_LEFT -column 0 -row 2 -columnspan 1 -sticky we
    grid $::w.outerframe.frame3B_row3_RIGHT -column 1 -row 2 -columnspan 9 -sticky we
    grid $::w.outerframe.frame4A_row4_LEFT -column 0 -row 3 -columnspan 1 -sticky we
    grid $::w.outerframe.frame4B_row4_RIGHT -column 1 -row 3 -columnspan 9 -sticky we
    grid $::w.outerframe.frame5_row5 -column 0 -row 4 -columnspan 10 -sticky s

    In my poor understanding, the second line (at least, among others) establishes that I want to treat the entire window like it has 10 columns.

    That is what you have told grid.

    So I expect the "3A" frame (label) to occupy exactly 1/10 of the window's length,

    Ah, herein lies the confusion. length != column

    9 out of 10 columns does not imply 90% of width (except in the instance
    of exactly equal width columns -- but grid does not guarantee exactly
    equal width columns). Do not think of columns in grid as anything
    other than relative positioning compared to other widgets. Actual
    screen width, of any given column, will depend upon the size needed for
    any widgets in the cells.

    How can I bring that entry widget closer to the label widget, please?

    Does this layout match your expectations?:

    Note several changes:

    1) Got rid of 'eval destroy ...' and made it just 'destroy ...' (no
    need for eval here, and in general, for 99% of typical Tcl/Tk
    programming, one never need touch 'eval' at all)

    2) Removed all the extraneous frames (they were also likely causing you
    part of your trouble, because you also have to properly configure each
    of them for the final grid to layout properly)

    3) Simplified the widget definitions, and caputured the full widget
    names in variables for the final 'gridding'.

    4) Switched to grid "relative placement" symbols.

    5) Dropped the "10 columns" (remember, columns!=length) - you have only
    two columns at most in your widget layout, so this new grid has only
    two columns.

    4) Enabled 'columnconfigure -weight 1' on column 1 (this was the
    'setting' you had not yet toggled on, and it is the critical one for
    getting many grid layouts to finally 'snap' into shape much of the
    time. This is also the 'setting' I alluded to at the beginning of this
    post.

    --- code ---

    package require Tk
    package require tile
    ttk::style theme use alt
    wm withdraw .
    destroy [winfo children .]
    catch {destroy .manage}
    set ::w [toplevel .manage]
    wm resizable $::w 1 1
    tk appname "W"
    wm title $::w "W"

    set of [frame $::w.outerframe]

    set topLabel [label $of.topLabel -font {Arial 16} -anchor center -text "TITLE" \
    -justify center -relief ridge -borderwidth 4]

    set 2ndLineLabel [label $of.2ndLineLabel -font {Arial 16} -anchor center \
    -text "the presence of some possibly very long text here, it could happen" \
    -relief ridge -borderwidth 4]

    set leftLabel [label $of.leftLabel -font {Arial 16} -anchor w -text "Input:" \
    -background #ffffff -relief ridge -borderwidth 4]

    set rightEntry [entry $of.rightEntry -background #ffffff -width 24 -text "type" \
    -background #ffffff -relief ridge -borderwidth 4]

    $rightEntry insert end "3B RIGHT"

    set infoLabel [label $of.infoLabel -background #ffffff -anchor w \
    -font {Arial 16} -text
  • From Luc@21:1/5 to Rich on Sun Oct 16 21:47:08 2022
    On Sun, 16 Oct 2022 14:43:52 -0000 (UTC), Rich wrote:

    Does this layout match your expectations?:

    Note several changes:

    1) Got rid of 'eval destroy ...' and made it just 'destroy ...' (no
    need for eval here, and in general, for 99% of typical Tcl/Tk
    programming, one never need touch 'eval' at all)

    2) Removed all the extraneous frames (they were also likely causing you
    part of your trouble, because you also have to properly configure each
    of them for the final grid to layout properly)

    3) Simplified the widget definitions, and caputured the full widget
    names in variables for the final 'gridding'.

    4) Switched to grid "relative placement" symbols.

    5) Dropped the "10 columns" (remember, columns!=length) - you have only
    two columns at most in your widget layout, so this new grid has only
    two columns.

    4) Enabled 'columnconfigure -weight 1' on column 1 (this was the
    'setting' you had not yet toggled on, and it is the critical one for
    getting many grid layouts to finally 'snap' into shape much of the
    time. This is also the 'setting' I alluded to at the beginning of this
    post.

    --- code ---

    Thank you for your input. It helps.

    However, for the sake of science...

    You did bring the right-hand entry box closer to the left-hand label.

    But what if I tell you it's not close enough?

    Sure, that can be fixed. Replace...

    grid $leftLabel $rightEntry -ipadx 10 -ipady 10 -sticky news

    ...with

    grid $leftLabel $rightEntry -ipadx 1 -ipady 10 -sticky news

    But either way, everything is aligned left too close to the leftmost wall.
    Note that my original code provides a certain padding, some kind of indentation. That was thanks to my frames that you referred to as
    "extraneous."

    New question: can you restore my "indentation" AND still bring the entry box even closer to the label, the way it looks with -ipadx 1?

    Note: I'm not testing you. I'm testing grid. I suspect grid cannot deliver
    what I want. The widget management is flawed. I still haven't tried pack,
    but I will. I am actually studying grid to see if it is any better.
    It doesn't look good so far.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Mon Oct 17 02:09:19 2022
    Luc <[email protected]> wrote:
    New question: can you restore my "indentation" AND still bring the
    entry box even closer to the label, the way it looks with -ipadx 1?

    Does this mod move it closer to what you want to achieve?

    --- luc.mod.post1 2022-10-16 22:08:24.167279780 -0400
    +++ luc.mod 2022-10-16 22:08:01.223890630 -0400
    @@ -19,7 +19,7 @@
    -relief ridge -borderwidth 4]

    set leftLabel [label $of.leftLabel -font {Arial 16} -anchor w -text "Input:" \ - -background #ffffff -relief ridge -borderwidth 4]
    + -background #ffffff -relief ridge -borderwidth 4 -padx 10]

    set rightEntry [entry $of.rightEntry -background #ffffff -width 24 -text "type" \
    -background #ffffff -relief ridge -borderwidth 4]
    @@ -27,7 +27,7 @@
    $rightEntry insert end "3B RIGHT"

    set infoLabel [label $of.infoLabel -background #ffffff -anchor w \
    - -font {Arial 16} -text "Info" -relief ridge -borderwidth 4]
    + -font {Arial 16} -text "Info" -relief ridge -borderwidth 4 -padx 10]

    set explainLabel [label $of.explainLabel -font {Arial 16} -background #ffffff \
    -anchor w -text "some more text here" -relief ridge -borderwidth 4]
    @@ -40,8 +40,8 @@

    grid $topLabel - -ipadx 10 -ipad
  • From Rich@21:1/5 to Luc on Mon Oct 17 01:58:07 2022
    Luc <[email protected]> wrote:
    On Sun, 16 Oct 2022 14:43:52 -0000 (UTC), Rich wrote:

    Does this layout match your expectations?:

    Note several changes:

    1) Got rid of 'eval destroy ...' and made it just 'destroy ...' (no
    need for eval here, and in general, for 99% of typical Tcl/Tk
    programming, one never need touch 'eval' at all)

    2) Removed all the extraneous frames (they were also likely causing you
    part of your trouble, because you also have to properly configure each
    of them for the final grid to layout properly)

    3) Simplified the widget definitions, and caputured the full widget
    names in variables for the final 'gridding'.

    4) Switched to grid "relative placement" symbols.

    5) Dropped the "10 columns" (remember, columns!=length) - you have only
    two columns at most in your widget layout, so this new grid has only
    two columns.

    4) Enabled 'columnconfigure -weight 1' on column 1 (this was the
    'setting' you had not yet toggled on, and it is the critical one for
    getting many grid layouts to finally 'snap' into shape much of the
    time. This is also the 'setting' I alluded to at the beginning of this
    post.

    --- code ---

    Thank you for your input. It helps.

    However, for the sake of science...

    You did bring the right-hand entry box closer to the left-hand label.

    But what if I tell you it's not close enough?

    Sure, that can be fixed. Replace...

    grid $leftLabel $rightEntry -ipadx 10 -ipady 10 -sticky news

    ...with

    grid $leftLabel $rightEntry -ipadx 1 -ipady 10 -sticky news

    But either way, everything is aligned left too close to the leftmost wall. Note that my original code provides a certain padding, some kind of indentation. That was thanks to my frames that you referred to as "extraneous."

    New question: can you restore my "indentation" AND still bring the entry box even closer to the label, the way it looks with -ipadx 1?

    Let me make sure I understand, you want "Input:" and "Info" to be
    spaced away from the left wall, while bringing the boundary between
    "Input:" and "3B right" closer together?

    Note: I'm not testing you. I'm testing grid. I suspect grid cannot deliver what I want. The widget management is flawed. I still haven't tried pack,
    but I will. I am actually studying grid to see if it is any better.
    It doesn't look good so far.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Tue Oct 18 00:30:57 2022
    Luc <[email protected]> wrote:
    On Mon, 17 Oct 2022 02:09:19 -0000 (UTC), Rich wrote:

    Can you please tell me how to apply those changes? I tried:

    $ patch new m2.tcl
    patch: **** Only garbage was found in the patch input.

    No offense. Patch called it garbage, not me. :-D

    patch takes the patch file on stdin. You'd have the original file "I
    named it 'luc.mod'" in the current directory, and in that directory
    you'd do:

    patch < patch.file

    and it will apply.


    However, the changes are small enough (lines starting with - are
    removed, those with + are added) to simply apply by hand.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to Rich on Mon Oct 17 21:21:13 2022
    On Mon, 17 Oct 2022 02:09:19 -0000 (UTC), Rich wrote:

    Luc <[email protected]> wrote:
    New question: can you restore my "indentation" AND still bring the
    entry box even closer to the label, the way it looks with -ipadx 1?

    Does this mod move it closer to what you want to achieve?

    --- luc.mod.post1 2022-10-16 22:08:24.167279780 -0400
    +++ luc.mod 2022-10-16 22:08:01.223890630 -0400
    @@ -19,7 +19,7 @@
    -relief ridge -borderwidth 4]

    set leftLabel [label $of.leftLabel -font {Arial 16} -anchor w -text
    "Input:" \
    - -background #ffffff -relief ridge -borderwidth 4]
    + -background #ffffff -relief ridge -borderwidth 4 -padx 10]

    set rightEntry [entry $of.rightEntry -background #ffffff -width 24 -text "type" \ -background #ffffff -relief ridge -borderwidth 4]
    @@ -27,7 +27,7 @@
    $rightEntry insert end "3B RIGHT"

    set infoLabel [label $of.infoLabel -background #ffffff -anchor w \
    - -font {Arial 16} -text "Info" -relief ridge -borderwidth 4]
    + -font {Arial 16} -text "Info" -relief ridge -borderwidth 4 -padx
    10]
    set explainLabel [label $of.explainLabel -font {Arial 16} -background #ffffff \ -anchor w -text "some more text here" -relief ridge
    -borderwidth 4] @@ -40,8 +40,8 @@

    grid $topLabel - -ipadx 10 -ipady 1 -sticky news
    grid $2ndLineLabel - -ipadx 10 -ipady 12 -sticky news
    -grid $leftLabel $rightEntry -ipadx 10 -ipady 10 -sticky news
    -grid $infoLabel $explainLabel -ipadx 10 -ipady 10 -sticky news
    +grid $leftLabel $rightEntry -ipady 10 -sticky news
    +grid $infoLabel $explainLabel -ipady 10 -sticky news
    grid $okcancel -

    grid columnconfigure $of 1 -weight 1
    ************************

    Can you please tell me how to apply those changes? I tried:

    $ patch new m2.tcl
    patch: **** Only garbage was found in the patch input.

    No offense. Patch called it garbage, not me. :-D

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to All on Sun Oct 23 19:30:40 2022
    On Mon, 17 Oct 2022 02:09:19 -0000 (UTC), Rich wrote:

    Can you please tell me how to apply those changes? I tried:

    $ patch new m2.tcl
    patch: **** Only garbage was found in the patch input.

    No offense. Patch called it garbage, not me. :-D

    patch takes the patch file on stdin. You'd have the original file "I
    named it 'luc.mod'" in the current directory, and in that directory
    you'd do:

    patch < patch.file

    and it will apply.


    However, the changes are small enough (lines starting with - are
    removed, those with + are added) to simply apply by hand.


    I'm closing off this thread just to thank Rich for all the help.
    It was educational.

    But I ended up rewriting the whole thing using only pack instead of
    grid and now it looks just the way I wanted.

    I guess I learned not to ever mess with grid again.

    Thank you.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)