Skip to content

gh-153716: Harden ttk/tkinter GUI tests against display scaling#153717

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-153716-harden-gui-tests-dpi
Jul 15, 2026
Merged

gh-153716: Harden ttk/tkinter GUI tests against display scaling#153717
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-153716-harden-gui-tests-dpi

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 14, 2026

Copy link
Copy Markdown
Member

Several test_ttk and test_tkinter GUI tests probed widget elements at fixed pixel coordinates (typically (5, 5)) or scanned a fixed pixel range (range(5, 100, 5), range(0, 100, 10)). ttk element geometry — tab padding, the focus ring, trough insets, row height — scales with the display DPI (tk scaling), so a fixed pixel that lands on the intended element at a normal scaling lands on a different element, or misses it entirely, at a high DPI. The test then either fails outright or passes by accident, its assertion accepting '' (the "nothing here" result) so it never actually exercises the behaviour it claims to.

This surfaces on Retina/HiDPI macOS (Homebrew Tk 9, scaling 2.0) and on any X11 display with a high -dpi.

The probe coordinates are now computed from each widget's own realized geometry instead of being hardcoded:

  • NotebookTest._tab_point() — a new helper returning a point that really lies on a given tab, via the ttk::notebook index @x,y subcommand. Used by test_traversal (which now also asserts the selection before and after the click) and test_tab_identifiers.
  • EntryTest.test_identify — probes the widget centre (winfo_width()/winfo_height()).
  • TreeviewTest.test_tag_bind — scans the real winfo_height() for item rows.
  • ScaleTest.test_identify — probes the trough centreline from Scale.coords().

This makes the tests position-, theme-, platform- and scaling-agnostic and removes the darwin coordinate special-cases.

Test-only change. Verified across scaling 1–6 (DPI 72–432) on Tk 8.6.17 and 9.0.3.

🤖 Generated with Claude Code

Compute probe coordinates from the widget's own realized geometry
instead of hardcoding pixels such as (5, 5), which land on a different
element, or miss it entirely, at a high display scaling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ixed pixel

The arrow-click test helpers probed a fixed x = width - 5, which at a
high display scaling on Tk 9.1 lands in the arrow element's right-hand
border (the border scales with the DPI), so identify() there returns
'field' and the test fails.  Scan inward from the right edge for the
arrow element instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip news labels Jul 15, 2026
@serhiy-storchaka serhiy-storchaka merged commit 87411d0 into python:main Jul 15, 2026
56 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the gh-153716-harden-gui-tests-dpi branch July 15, 2026 03:06
@bedevere-app

bedevere-app Bot commented Jul 15, 2026

Copy link
Copy Markdown

GH-153737 is a backport of this pull request to the 3.15 branch.

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 87411d0742f070b1424c08b41cf3af49d377b215 3.13

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 15, 2026
@bedevere-app

bedevere-app Bot commented Jul 15, 2026

Copy link
Copy Markdown

GH-153738 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 15, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 15, 2026
GH-153717) (GH-153738)

Compute probe coordinates from each widget's own realized geometry
instead of hardcoding pixels such as (5, 5) or width - 5, which land on
a different element, or miss it entirely, at a high display scaling.
(cherry picked from commit 87411d0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Jul 15, 2026
GH-153717) (GH-153737)

Compute probe coordinates from each widget's own realized geometry
instead of hardcoding pixels such as (5, 5) or width - 5, which land on
a different element, or miss it entirely, at a high display scaling.
(cherry picked from commit 87411d0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bedevere-app

bedevere-app Bot commented Jul 15, 2026

Copy link
Copy Markdown

GH-153743 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 15, 2026
@serhiy-storchaka serhiy-storchaka removed their assignment Jul 15, 2026
serhiy-storchaka added a commit that referenced this pull request Jul 15, 2026
GH-153717) (GH-153743)

Compute probe coordinates from each widget's own realized geometry
instead of hardcoding pixels such as (5, 5) or width - 5, which land on
a different element, or miss it entirely, at a high display scaling.


(cherry picked from commit 87411d0)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant