| Ticket UUID: | aba849a99bbcfffae23e0147c313777edf6407b1 | |||
| Title: | ttk::style configure has no effect on options with a non-empty widget default (-justify, -anchor, ...) | |||
| Type: | Bug | Version: | 9.0.5 | |
| Submitter: | serhiy.storchaka | Created on: | 2026-09-13 18:36:37 | |
| Subsystem: | 88. Themed Tk | Assigned To: | jan.nijtmans | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Closed | Last Modified: | 2026-09-18 15:21:22 | |
| Resolution: | Fixed | Closed By: | jan.nijtmans | |
| Closed on: | 2026-09-18 14:44:59 | |||
| Description: |
In Tk 8.6 this centered the button text; in Tk 9.0 it has no effect: % ttk::style configure TButton -justify center % pack [ttk::button .b -text "Foo Bar\nSpam Eggs"] An element takes an option from the widget if the widget option is not NULL, and only otherwise from the style (InitializeElementRecord in ttkTheme.c). TIP #442 made -justify a widget option of ttk::button, ttk::checkbutton, ttk::radiobutton and ttk::menubutton with the default "left", so the style is never consulted. The same applies to -anchor of ttk::label ("w" since [6178610b1b], 8.6.12) and to -anchor, -font, -foreground, -justify and -wraplength of ttk::progressbar. This is the same bug as [b82bd4872b] (-compound), and the fix is the same: NULL defaults, so that the style is used when the widget option is not set. The element defaults keep the current behaviour when neither is set. Since TIP #613 the justify and anchor option types accept NULL. Reported against Python 3.14.7, which ships Tk 9.0: https://github.com/python/cpython/issues/157337 | |||
| User Comments: |
serhiy.storchaka added on 2026-09-18 15:21:22:
Thanks! For headings yes: the "center" default always overrides ttk::style configure Heading -anchor, so it is the same issue. For cells the fallback to TK_ANCHOR_W passed to Ttk_AnchorElement() still overrides the style; when the column has no -anchor, the text element should be left with its own -anchor from the style. A test with ttk::style configure would show whether it works. jan.nijtmans added on 2026-09-18 14:44:59: Many thanks! Everything is merged now to core-9-0-branch and trunk. Additional question: Should the same be done for the treeview as well? Like: [65e9cf08e8369c14] Thanks! serhiy.storchaka added on 2026-09-17 09:39:02: Tested on main (Linux, rebuilt at [2d75f9f662]): ttk::style -anchor/-justify/-font now take effect for ttk::label, ttk::button and ttk::progressbar, widget options still override the style, and the ttk tests pass. Thanks! Three small things were left out or introduced by the merge; follow-up on branch [aba849-followup]:
serhiy.storchaka added on 2026-09-17 09:38:08: Tested on main (Linux, rebuilt at [2d75f9f662]): ttk::style -anchor/-justify/-font now take effect for ttk::label, ttk::button and ttk::progressbar, widget options still override the style, and the ttk tests pass. Thanks! Three small things were left out or introduced by the merge; follow-up on branch [aba849-followup]:
jan.nijtmans added on 2026-09-15 20:04:05: Thanks, Csaba! And Serhiy Storchaka of course! Merged to 9.0 and 9.1 now. Please test, and report if there is something wrong still. nemethi (claiming to be Csaba Nemethi) added on 2026-09-15 18:03:17: Made a few small changes to account for a restriction imposed by nanosvg. Apart from this, the code works for me as expected. jan.nijtmans added on 2026-09-15 13:15:52: Proposed fix [3237786eb52cfdfc|here]. The "-foreground" option for ttk::label is not done: Allowing this option to be NULL gives crashes in the test suite, so that one will be more complicated. Ttk seems to be not prepared to accept a NULL-value of a TK_OPTION_COLOR. Can someone review/test, please (I'll let CI test it too)! oehhar added on 2026-09-14 08:14:00: Serhi, great ticket and patch including fix, documentation and test, thank you for this! I would love if a 2nd opinion would second the solution (Csaba, Jan). Then, we can merge. Thanks for all, Harald | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki