Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Issue with ttk::combobox and "state disabled"

58 views
Skip to first unread message

Torsten

unread,
Jul 31, 2022, 10:26:00 AM7/31/22
to
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.

nemethi

unread,
Jul 31, 2022, 11:52:23 AM7/31/22
to
Am 31.07.22 um 16:25 schrieb Torsten:
.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:csaba....@t-online.de

Schelte

unread,
Jul 31, 2022, 12:01:11 PM7/31/22
to
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.


0 new messages