Skip to content

Conversation

Akuli
Copy link
Collaborator

@Akuli Akuli commented Sep 26, 2025

The winfo_children() method returns a list of the child widgets of a widget. Previously I thought this could never be Toplevel widgets, but that is wrong: they can in fact be anything except tkinter.Tk.

>>> from tkinter import Tk, Toplevel, Button
>>> root = Tk()
>>> top = Toplevel()
>>> button = Button()
>>> root.winfo_children()
[<tkinter.Toplevel object .!toplevel>, <tkinter.Button object .!button>]
>>> 

Tk can never be the child of another widget, because it is a special widget and each instance of Tk is internally a whole new Tcl interpreter.

Ideally, the type of this would be Misc & ~Tk; that is, any widget except Tk. But because & and ~ operators on types don't exist yet, the best we can do is Widget | Toplevel. Misleadingly, Widget in tkinter means any widget except Tk or Toplevel, and Misc means any widget.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@Avasam Avasam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your explanation makes sense to me.

@Akuli Akuli merged commit 332fcab into main Sep 29, 2025
63 checks passed
@Akuli Akuli deleted the Akuli-patch-1 branch September 29, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants