• `pack/grid -in` depends on frame creation order ?

    From xol odho@21:1/5 to All on Sun Nov 6 21:51:21 2022
    Hello everyone. The quest for learning Tk goes on... so much to learn. So, today I have the following question.

    I'm trying to understand what causes the difference in behavior between
    the following two scripts, A and B:

    A:

    frame .f
    button .b -text hallo
    pack .f
    pack .b -in .f

    B:

    button .b -text hallo
    frame .f
    pack .f
    pack .b -in .f


    A and B are the almost the same but just with .f and .b created in
    different order. I was expecting these two variations to behave the same,
    but they don't: when .f is created before .b, the button .b appears, the
    second version doesn't show the button.

    The same happens if "grid" is used instead of "pack".

    Why is this?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Mon Nov 7 07:25:39 2022
    Am 07.11.2022 um 06:51 schrieb xol odho:
    Hello everyone. The quest for learning Tk goes on... so much to learn. So, today I have the following question.

    I'm trying to understand what causes the difference in behavior between
    the following two scripts, A and B:

    A:

    frame .f
    button .b -text hallo
    pack .f
    pack .b -in .f

    B:

    button .b -text hallo
    frame .f
    pack .f
    pack .b -in .f


    A and B are the almost the same but just with .f and .b created in
    different order. I was expecting these two variations to behave the same,
    but they don't: when .f is created before .b, the button .b appears, the second version doesn't show the button.

    The same happens if "grid" is used instead of "pack".

    Why is this?

    You have two points to consider:
    - tabbing order
    - clipping order

    Clipping order is set by creation time.
    It may be modified by the raise command.
    So, "raise .b" will probably show the button.
    As a rule of thumb, first create the parents, then the childs.

    The 2nd point of this complex is tabbing order.

    Try
    pack [entry .1] -side top
    pack [entry .2] -side top
    pack [entry .3] -side top

    and

    pack [entry .1] -side top
    pack [entry .3] -side bottom
    pack [entry .2] -side top

    and use the tab-key to cycle between the widgets.

    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From xol odho@21:1/5 to All on Mon Nov 7 12:00:40 2022
    Hi, thanks for the answer!
    It's very clear now.

    Seems I had read about this in Ousterhout's book and totally forgot about it.
    I usually create the frames before the widgets, that's why I forgot about the potential need to use `raise`. I'll keep it in mind :)

    Actually it is explained on page 406 of the 2nd edition of that book, (section 21.7 Hierarchical Geometry Management).

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