Skip to content

Harden ttk/tkinter GUI tests against display scaling (DPI) #153716

Description

@serhiy-storchaka

Several test_ttk and test_tkinter GUI tests probe widget elements at fixed pixel coordinates (typically (5, 5)) or scan a fixed pixel range (e.g. 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.

This produces two failure modes:

  • The test fails outright at high DPI (e.g. NotebookTest.test_traversal clicked (5, 5), which no longer lands on a tab at scaling 2.0).
  • The test passes by accident — its assertion accepts '' (the "nothing here" result), so it never actually exercises the behaviour it claims to (e.g. ScaleTest.test_identify always identified '' at (5, 5); the darwin branch of test_traversal asserted identify(5, 5) == '').

Both are latent: they surface on Retina/HiDPI macOS (Homebrew Tk 9, scaling 2.0) and any X11 display with a high -dpi.

Fix: compute probe coordinates from the widget's own realized geometry instead of hardcoding pixels — ttk::notebook index @x,y for a point guaranteed to lie on a given tab, winfo_width()/winfo_height() centre for Entry, Scale.coords() for the trough, and scanning the real winfo_height() for Treeview rows. This makes the tests position-, theme-, platform- and scaling-agnostic, and removes the darwin coordinate special-cases.

Test-only change. Affects test_ttk (EntryTest.test_identify, NotebookTest.test_tab_identifiers, NotebookTest.test_traversal, TreeviewTest.test_tag_bind) and test_tkinter (ScaleTest.test_identify). Verified across scaling 1–6 (DPI 72–432) on Tk 8.6.17 and 9.0.3.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixestestsTests in the Lib/test dirtopic-tkinter

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions