• width of tk_optionMenu

    From shenyeh.chen@gmail.com@21:1/5 to All on Thu Oct 28 00:33:54 2021
    Hi everyone,

    I am wondering if there is a way to set a fixed width for the tk_optionManu ?

    I am using a list with several strings as the option list. The strings have different length. So that when the user pulls down the menu and select, the final width of the menu will changed according to its string length.

    How do I give a fixed width to the whole option menu ?

    Regards
    S-Y. Chen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From shenyeh.chen@gmail.com@21:1/5 to Ralf Fassel on Thu Oct 28 01:24:11 2021
    On Thursday, October 28, 2021 at 4:18:52 PM UTC+8, Ralf Fassel wrote:
    * "shenye...@gmail.com" <shenye...@gmail.com>
    | How do I give a fixed width to the whole option menu ?
    Configure the -width of it > 0, and it will stay fixed size.

    You could get the max length of all entries and use that as -width
    (probably also checking for a sensible max width if there happen to be
    very long entries).

    HTH
    R'

    Yes I did, as the scripts below

    ==============
    set w_opt [eval tk_optionMenu .form.optionmenu_1 var1 $list 1]
    $w_opt configure -width 45
    =============

    But I then got the error message : unknown option "-width"

    Regards
    S-Y. Chen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Thu Oct 28 10:18:47 2021
    * "shenye...@gmail.com" <shenyeh.chen@gmail.com>
    | How do I give a fixed width to the whole option menu ?

    Configure the -width of it > 0, and it will stay fixed size.

    You could get the max length of all entries and use that as -width
    (probably also checking for a sensible max width if there happen to be
    very long entries).

    HTH
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Thu Oct 28 11:17:14 2021
    * "shenye...@gmail.com" <shenyeh.chen@gmail.com>
    | On Thursday, October 28, 2021 at 4:18:52 PM UTC+8, Ralf Fassel wrote:
    | > * "shenye...@gmail.com" <shenye...@gmail.com>
    | > | How do I give a fixed width to the whole option menu ?
    | > Configure the -width of it > 0, and it will stay fixed size.
    | >
    | > You could get the max length of all entries and use that as -width
    | > (probably also checking for a sensible max width if there happen to be
    | > very long entries).

    | Yes I did, as the scripts below

    | ==============
    | set w_opt [eval tk_optionMenu .form.optionmenu_1 var1 $list 1]
    | $w_opt configure -width 45
    | =============

    | But I then got the error message : unknown option "-width"

    The manpage for tk_optionMenu says:

    The return value from tk_optionMenu is the name of the menu
    associated with pathName, so that the caller can change its
    configuration options or manip- ulate it in other ways.

    So try

    .form.optionmenu_1 configure -width 45

    instead (i.e. use the widget name you passed to tk_optionMenu, not the
    return value).

    HTH
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From shenyeh.chen@gmail.com@21:1/5 to Ralf Fassel on Fri Oct 29 01:31:11 2021
    On Thursday, October 28, 2021 at 5:17:17 PM UTC+8, Ralf Fassel wrote:
    * "shenye...@gmail.com" <shenye...@gmail.com>
    | On Thursday, October 28, 2021 at 4:18:52 PM UTC+8, Ralf Fassel wrote:
    | > * "shenye...@gmail.com" <shenye...@gmail.com>
    | > | How do I give a fixed width to the whole option menu ?
    | > Configure the -width of it > 0, and it will stay fixed size.
    | >
    | > You could get the max length of all entries and use that as -width
    | > (probably also checking for a sensible max width if there happen to be
    | > very long entries).

    | Yes I did, as the scripts below

    | ==============
    | set w_opt [eval tk_optionMenu .form.optionmenu_1 var1 $list 1]
    | $w_opt configure -width 45
    | =============

    | But I then got the error message : unknown option "-width"
    The manpage for tk_optionMenu says:

    The return value from tk_optionMenu is the name of the menu
    associated with pathName, so that the caller can change its
    configuration options or manip- ulate it in other ways.

    So try

    .form.optionmenu_1 configure -width 45

    instead (i.e. use the widget name you passed to tk_optionMenu, not the
    return value).

    HTH
    R'

    Yes that works now. Thanks !
    However, now the strings of the pull-down menu are aligned in the center. Is there any way to align all the strings to left/right ?
    In the pull-down menu, they just all appear aligned to the left. After the option is selected, the string in the box are all center aligned.

    Thanks again for the help.

    S-Y. Chen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to shenye...@gmail.com on Fri Oct 29 10:51:12 2021
    On 29/10/2021 10:31, shenye...@gmail.com wrote:
    In the pull-down menu, they just all appear aligned to the left. After the option is selected, the string in the box are all center aligned.

    Of course, similar to the -witdh option, you can also configure the
    -anchor option.


    Schelte.

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