Tk Source Code

View Ticket
Login
Ticket UUID: 4d0a6f32b79a6faac7399fc2efefb108722f01a
Title: Unique behavior of some options in the message widget in 8.7/9.0
Type: Bug Version: 8.7b1+, 9.0b2+
Submitter: serhiy.storchaka Created on: 2024-06-05 12:54:10
Subsystem: 23. Option Parsing Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2024-06-21 10:54:31
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2024-06-21 10:54:31
Description:

Options -highlightthickness and -padx (but not -pady) in the message widget (and only in this widget) changed its behavior for negative argument in 8.7/9.0.

In Tk 8.6 (and older):

% message .m -text Text -highlightthickness -2 -padx -2 -pady -2
.m
% .m configure -highlightthickness
-highlightthickness highlightThickness HighlightThickness 0 0
% .m configure -padx
-padx padX Pad -1 -2
% .m configure -pady
-pady padY Pad -1 -2

In Tk 9.0 and 8.7:

% message .m -text Text -highlightthickness -2 -padx -2 -pady -2
.m
% .m configure -highlightthickness
-highlightthickness highlightThickness HighlightThickness 0 -2
% .m configure -padx
-padx padX Pad {} {}
% .m configure -pady
-pady padY Pad {} -2

In all other widgets the behavior of these options was not changed. It is weird that it is not even consistent between -padx and -pady options. Note also that the change for -highlightthickness and -padx are opposite: -highlightthickness converted a negative value to 0, while -padx leaved it as is, but now -highlightthickness leaves it as is and -padx converts it to an empty string. Is there some bug?

I expect at least consistency between -padx and -pady and preferably consistency across widgets. Such special case requires adding a special case in Tkinter tests, but it looks not like intentional change.

User Comments: jan.nijtmans added on 2024-06-21 10:54:31:

> `message` still has a unique behavior

Indeed, but that's due to this special behavior: if -padx is negative it's set to the ascent of the font divided by 2. If -pady is negative it's set to the ascent of the font divided by 4. This behavior is not documented, but it's implemented this way.

So, if -padx/-pady would be reset to 0 for negative values, the current behavior would change, especially for big fonts.

The -elementborderwidth option for the scrollbar has a similar special behavior, but this one is documented.

TODO: fix the documentation


serhiy.storchaka added on 2024-06-21 10:06:16:

message still has a unique behavior. It is the only widget that resets negative -padx and -pady values to "" in 9.0 and -1 in 8.7. All other widgets that reset the value (button, checkbutton, radiobutton, label, menubutton and tk_optionMenu), reset it to 0.


jan.nijtmans added on 2024-06-14 22:20:49:

Should be all OK now for buttons and message

Closing


jan.nijtmans added on 2024-06-10 20:17:57:

> So, buttons and message (and ttk) do it correctly

Thinking more about it, this is not true! Something what was never considered is caching the values of padX/padY/borderWidth/highlightWidth: Now that Tk uses scaling we cannot cache the integer values any more, since they need to be re-calculated when the scaling changes. And - also - padX/padY needs to be re-calculated when the value is "-1" and the message font changes.

In [653813f7aeb1d3f3|this] commit, all of that should be corrected (for buttons and messages). Let's see what GITHUB thinks of that.


jan.nijtmans added on 2024-06-07 07:28:33:

> As for `-highlightthickness`, its behavior is not consistent across widgets.

I created a [New ticket] for this, since `-highlightthickness` turns out not the only one with this inconsistancy. There are many more.

Closing this ticket.

Keep your reports coming, they are very much appreciated!


jan.nijtmans added on 2024-06-06 13:37:49:

Actually, everywhere TK_OPTION_PIXELS is used, the behavior should be to preserve the value. So, buttons and message (and ttk) do it correctly. When TK_CONFIG_PIXELS is used, that's the old config code: preserving the value is not possible.

This means that 'text', 'entry', 'frame', 'listbox', 'menubuttons' and 'scale' should move to the other group as well.....

But that's work for another ticket, I think.


serhiy.storchaka added on 2024-06-06 12:48:50:

As for -highlightthickness, its behavior is not consistent across widgets. In most widgets (canvas, entry, frame, labelframe, listbox, menubutton, message, scale, scrollbar, spinbox, text, tk_optionMenu, toplevel) it crops negative values to 0. In some widgets (button, checkbutton, label, radiobutton) it preserves negative values. It was so since at least 8.4. Now message has been moved from one group to other.


jan.nijtmans added on 2024-06-05 21:47:05:

Should be fixed now in core-8-branch and trunk.

"message" now works the same (regarding -highlightthickness/-padx/-pady) as "button".

The default for -padx/-pady is -1 for Tk 8.7 (unchanged) and "" for Tk 9.0. That doesn't mean that there is no padding, it just means that the padding has the default value (ascent/2 resp. ascent/4).


serhiy.storchaka added on 2024-06-05 16:18:54:

I'm not very good with fossil to test this change, it looks fine, but it only fixes the difference between -padx and -pady in the message widget, isn't? The behavior is different in other widgets.

% button .b -text Text -highlightthickness -2 -padx -2 -pady -2
.b
% .b configure -highlightthickness
-highlightthickness highlightThickness HighlightThickness 1 -2
% .b configure -padx
-padx padX Pad 3m -2
% .b configure -pady
-pady padY Pad 1m -2


jan.nijtmans added on 2024-06-05 14:14:03:

Does [35f81e52c42c08cf|this] work better?

The change in "-highlightthickness" wat intentional: Tk should never modify given values, it should just return what's given.

For Tk 9.0 the idea was to change the default from -1 to "". But that wasn't done correctly ...


jan.nijtmans added on 2024-06-05 13:18:22:

Thanks! I will have a look