• Issue with ttk::combobox and "state disabled"

    From Torsten@21:1/5 to All on Sun Jul 31 07:25:57 2022
    I have a ttk::combobox that is part of an optional feature in my program. When the feature is switched off, I recursively grey out all child widgets setting "state disabled".
    This works fine, until I click on the combobox and then switch off the feature. I now get the following error:

    bad option "state": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview

    The error message is from a listbox that seems to "implement" the combobox. In total, four child widgets are added:

    .mycombobox.popdown
    .mycombobox.popdown.f
    .mycombobox.popdown.f.sb
    .mycombobox.popdown.f.l

    For the first three widgets I can set "state disabled". A listbox widget also has the option state, so why the error message?

    I could disable only the combobox, but that would require special handling of comboboxes when recursively going over all child widgets.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From nemethi@21:1/5 to All on Sun Jul 31 17:52:18 2022
    Am 31.07.22 um 16:25 schrieb Torsten:
    I have a ttk::combobox that is part of an optional feature in my program. When the feature is switched off, I recursively grey out all child widgets setting "state disabled".
    This works fine, until I click on the combobox and then switch off the feature. I now get the following error:

    bad option "state": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview

    The error message is from a listbox that seems to "implement" the combobox. In total, four child widgets are added:

    .mycombobox.popdown
    .mycombobox.popdown.f
    .mycombobox.popdown.f.sb
    .mycombobox.popdown.f.l

    For the first three widgets I can set "state disabled". A listbox widget also has the option state, so why the error message?

    I could disable only the combobox, but that would require special handling of comboboxes when recursively going over all child widgets.

    .mycombobox.popdown.f is a ttk::frame and mycombobox.popdown.f.sb is a ttk::scrollbar, hence for both the associated Tcl command has the
    "state" subcommand.

    OTOH, .mycombobox.popdown is a toplevel and
    .mycombobox.popdown.f.l is a listbox widget, hence for both the
    associated Tcl command has _no_ "state" subcommand. The listbox supports
    the "-state" configuration option instead, hence you can disable it via

    .mycombobox.popdown.f.l configure -state disabled

    Note, however, that the four descendants of the combobox are created on
    demand, they won't yet exist when the widget gets created. In addition,
    it is not necessary at all to disable the last three of them -- it fully suffices to disable the combobox itself via

    .mycombobox state disabled

    --
    Csaba Nemethi https://www.nemethi.de mailto:[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to Torsten on Sun Jul 31 18:01:06 2022
    On 31/07/2022 16:25, Torsten wrote:
    bad option "state": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview

    The error message is from a listbox that seems to "implement" the combobox. In total, four child widgets are added:

    .mycombobox.popdown
    .mycombobox.popdown.f
    .mycombobox.popdown.f.sb
    .mycombobox.popdown.f.l

    For the first three widgets I can set "state disabled". A listbox widget also has the option state, so why the error message?

    A listbox has a "state" option, but not a "state" subcommand. You seem
    to be doing [.mycombobox.popdown.f.l state disabled], which is not valid
    for a listbox. Instead you should be using [.mycombobox.popdown.f.l
    configure -state disabled].

    This is true for other tk (i.e. non-ttk) widgets too. So your procedure
    that recursively goes over all widgets should be checking the type of
    widget to know how to properly disable it, and if that's even possible
    (you cant disable a tk::frame, for example). Without that step, the proc
    will fail on any tk widget.

    The type of the widget can be queried with [winfo class mycombobox.popdown.f.l], which returns the normal value for a tk
    listbox: Listbox.


    Schelte.

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