Tk Source Code

View Ticket
Login
Ticket UUID: da23032e6ad6e3b8dc658453552e71d101ae5004
Title: ttk::combobox: Returned index is {} instead of expected -1
Type: Bug Version: Current
Submitter: stu Created on: 2023-07-21 16:29:18
Subsystem: 88. Themed Tk Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-01 14:52:39
Resolution: Wont Fix Closed By: nemethi
    Closed on: 2026-10-01 14:43:31
Description:
ttk::combobox .c ; .c current

Returns {} instead of the expected -1.

The docs say -1 should be the return value.

I realize this is from recent indexing changes.
Maybe other widgets have this problem as well.


Also, there is no bug tracker category for ttk::combobox.
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-10-01 14:43:31:

Closing the ticket again.


stu added on 2026-10-01 14:37:28:
I don't think this needs re-opening; I doubt it's going to change, and I accept that.
I just wanted to register my thoughts on the subject.
Thanks.

serhiy.storchaka added on 2026-09-30 20:14:33:

Reopened, but I think it is too late to revert this now. The change was intentional and has been in Tk since 9.0, and programs which were broken by it have probably already been adapted, so reverting it could break them again.


stu added on 2026-09-30 19:26:04:
For the record, I still don't agree with this.
The comparison  "" < 0  is at minimum wrong-looking.


"Actually, checking whether [.c current] equals -1 has never been the recommended style."

[Citation Needed]

serhiy.storchaka added on 2026-09-30 15:58:02:

This is the intended change of TIP 577 in Tk 9.0. The documentation has been updated in [5471e09e40]: current returns an empty string if the current value is not in the list of -values. As noted above, [.c current] < 0 works with both 8.6 and 9.0.


nemethi (claiming to be Csaba Nemethi) added on 2023-09-15 17:02:38:
To check whether [.c current] is a valid combobox index, you should use code like

    if {[.c current] < 0} {
        puts "The current value does not appear in the list of -values."
    }

This works regardless of the Tk version, because "" < 0 holds true just like -1 < 0.  Actually, checking whether [.c current] equals -1 has never been the recommended style.

chrstphrchvz added on 2023-07-21 20:42:58:

Subscribing myself for updates.


stu added on 2023-07-21 18:39:16:
I think that change will break a lot of code.

jan.nijtmans added on 2023-07-21 17:02:01:

See https://core.tcl-lang.org/tips/doc/trunk/tip/577.md. This is intended.

Time to update the documentation ....

Thanks!