• menu entryconfigure numerical labels

    From Ralf Fassel@21:1/5 to All on Tue Oct 10 16:57:24 2023
    I have a menu like this:

    menu .m -tearoff false
    .m add radiobutton -label 2 -value 2
    .m add radiobutton -label foo -value foo

    .m entrycget 0 -value
    2
    .m entrycget 1 -value
    foo

    Now

    .m entryconfigure 2 -value two

    fails to configure the first menu entry, since the "2" is taken as
    numerical index, and thus the last entry is configured instead:

    % .m entrycget 0 -value
    2
    % .m entrycget 1 -value
    two

    Is there some way to "configure-by-numerical-label" other than iterating
    over the menu and checking whether the label matches the desired value?

    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Griffiths@21:1/5 to Ralf Fassel on Tue Oct 10 14:11:14 2023
    On Tuesday, 10 October 2023 at 15:57:30 UTC+1, Ralf Fassel wrote:
    I have a menu like this:

    menu .m -tearoff false
    .m add radiobutton -label 2 -value 2
    .m add radiobutton -label foo -value foo

    .m entrycget 0 -value
    2
    .m entrycget 1 -value
    foo

    Now

    .m entryconfigure 2 -value two

    fails to configure the first menu entry, since the "2" is taken as
    numerical index, and thus the last entry is configured instead:

    % .m entrycget 0 -value
    2
    % .m entrycget 1 -value
    two

    Is there some way to "configure-by-numerical-label" other than iterating over the menu and checking whether the label matches the desired value?

    R'
    The index for menus follow the rules for [string match]; as it does various forms of matching (including wildcard), you can use \ to indicate a literal character. So if you use {\2} for your index, it doesn't get treated as a numerical index and instead
    looks for a label matching the literal character "2".

    .m entrycget {\2} -value

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Wed Oct 11 10:58:42 2023
    * Mike Griffiths <[email protected]>
    | On Tuesday, 10 October 2023 at 15:57:30 UTC+1, Ralf Fassel wrote:
    | > I have a menu like this:
    | >
    | > menu .m -tearoff false
    | > .m add radiobutton -label 2 -value 2
    | > .m add radiobutton -label foo -value foo
    | >
    --<snip-snip>--
    | >
    | > Is there some way to "configure-by-numerical-label" other than iterating
    | > over the menu and checking whether the label matches the desired value?
    | >
    | The index for menus follow the rules for [string match]; as it does
    | various forms of matching (including wildcard), you can use \ to
    | indicate a literal character. So if you use {\2} for your index, it
    | doesn't get treated as a numerical index and instead looks for a label
    | matching the literal character "2".

    | .m entrycget {\2} -value

    Mike,
    great, exactly what I am looking for! And since this is documented
    behaviour, it is not even a 'hack' :-)

    TNX
    R'

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