Skip to content

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

Closed

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

Activity

  1. added a commit that references this issue on Jul 14, 2026
  2. terryjreedy commented on Jul 15, 2026

    @terryjreedy
    Member

    I believe test_idle has a few test with hard-coded pixel coordinates. Did you, or could you, include test_idle with test_tkinter/ttk in your hi-scale tests?

  3. added 3 commits that reference this issue on Jul 15, 2026
  4. serhiy-storchaka commented on Jul 15, 2026

    @serhiy-storchaka
    MemberAuthor

    Opened #153741 for IDLE tests.

  5. added
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    on Jul 15, 2026
  6. added a commit that references this issue on Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions