Tk Source Code

View Ticket
Login
Ticket UUID: 450a726f4a069c42c633c06f2054135898d18f78
Title: Inconsistent behavior of -underline option in 8.7
Type: Bug Version: 8.7b1+, 9.0b2+
Submitter: serhiy.storchaka Created on: 2024-06-05 13:17:54
Subsystem: 23. Option Parsing Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2024-06-09 17:40:09
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2024-06-09 17:40:09
Description:

The -underline option converts an empty value to -1 in non-themed widgets on 8.7 and leaves it an empty string in themed widgets.

% button .b -underline ""
.b
% .b configure -underline
-underline underline Underline -1 -1
% ttk::button .b2 -underline ""
.b2
% .b2 configure -underline
-underline underline Underline -1 {}
It leaves it an empty string in all widgets in 9.0.
% button .b -underline ""
.b
% .b configure -underline
-underline underline Underline {} {}
% ttk::button .b2 -underline ""
.b2
% .b2 configure -underline
-underline underline Underline {} {}

It would be nice to have more consistency (it would require less special cases in the Tkinter tests). Perhaps some code was not yet backported to 8.7.

User Comments: jan.nijtmans added on 2024-06-06 11:11:02:

Indeed, it was a bug in Tcl. Should be fixed now.


jan.nijtmans added on 2024-06-05 20:42:37:

> I do not know whether this works as is expected, but "2-3" is translated to "end", while "2-4", "-1" and "-2" are translated to the default value. "end+2" is translated to "end+1".

More specific: "2-3" should be translated to the default value, so that's wrong!

"-1" and "-2" (and any negative value) are translated to the default value, that's how it should be. Internally, it's stored as INT_MIN.

"end+1" and "end+2" (generally: "end+?" for any value > 0) is translated to "end+1", that's correct too. Internally, it's stored as INT_MAX.

Conclusion: the "n-m" form needs correction when m > n. This looks like a bug in Tcl, not Tk. I'll investigate further


jan.nijtmans added on 2024-06-05 19:05:01:

That's certainly not how it is supposed to work .... Thanks!


serhiy.storchaka added on 2024-06-05 17:24:13:
I do not know whether this works as is expected, but "2-3" is translated to "end", while "2-4", "-1" and "-2" are translated to the default value. "end+2" is translated to "end+1".

serhiy.storchaka added on 2024-06-05 16:07:54:
Thank you for your explanation. I see that the difference between ttk and normal widgets is fundamental and unavoidable (at least in the nearest future), and the difference between 8.7 and 9.0 has a reason. I'll rewrite the Tkinter tests taking into account this information. In any case I need to add tests for a new syntax.

jan.nijtmans added on 2024-06-05 15:27:54:

Illustration:

$ wish8.6
% button .b -underline -2
.b
% .b configure -underline
-underline underline Underline -1 -2
% exit

$ wish8.7 % button .b -underline -2 .b % .b configure -underline -underline underline Underline -1 -1 % exit

$ wish9.0 % button .b -underline -2 .b % .b configure -underline -underline underline Underline {} {} %


jan.nijtmans added on 2024-06-05 15:20:05:

Explanation: The ttk widgets always store the full Tcl_Obj, the normal widgets only store an integer. Starting with Tk 8.7, this integer has a special meaning for negative values: -1 means "end", -2 means "end-1", INT_MIN means no underlining. That means that parsing "-2", "-1" or "" (which all mean: no underlining) all result in INT_MIN being stored internally, and cannot be distinguised any more. When reading back this value, the result is "-1" in Tk 8.7 and "" in Tk 9.0.

Since Tk 8.7 uses "-1" for "no underlining" (for compatibility with 8.6) and Tk 9.0 uses "", I see no way to change this without potentially sacrificing compatibility with Tk 8.6.

The best thing to do is expecting "-1" in all Tk 8.7 testcases and "" in all Tk 9.0 testcases for Tk widgets underlining.

Sorry!