Skip to content

gh-86657: Add a timeout parameter to tkinter wait_visibility()#152621

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-86657-wait-visibility-timeout
Open

gh-86657: Add a timeout parameter to tkinter wait_visibility()#152621
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:gh-86657-wait-visibility-timeout

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

Misc.wait_visibility() wraps the Tcl tkwait visibility command, which blocks until the window's visibility changes.
It can hang indefinitely — for example when called from a worker thread (gh-86657).

Add an optional keyword-only timeout argument (in seconds).
With a timeout the wait is reimplemented in Python on top of tkapp.dooneevent(), polling winfo_viewable(): it returns True once the window is viewable, or False if the timeout elapsed first (or the window was destroyed).
Without a timeout the behaviour is unchanged (the native tkwait call, always returns True).

Note: with a timeout the call waits until viewable (returning immediately if the window is already shown), which differs from the native "wait for a change" semantics — the poll behaviour is the useful one here.

Without a timeout wait_visibility() blocks until the visibility of the
widget changes, which can hang indefinitely (for example if the widget is
never mapped).  The new keyword-only timeout parameter bounds the wait and
returns whether the widget became viewable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33359418 | 📁 Comparing 48c1564 against main (c5043dc)

  🔍 Preview build  

3 files changed
± library/tkinter.html
± whatsnew/3.16.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant