I'm trying to understand some aspects of the Python TKinter package.
The package root cpython/Lib/tkinter is found on GitHub. I'm looking at the file cpython/Lib/tkinter/ttk.py. At line 512, this file defines a Widget class:
28 import tkinter
...
512 class Widget(tkinter.Widget):
"""Base class for Tk themed widgets."""
Figuring out what this is doing requires identifying this imported tkinter package. According to the Python docs, a directory containing a file __init__.py constitutes a regular package. Since [cpython/Lib/tkinter/__init__.py] exists, the directory cpython/Lib/tkinter/ is a regular package. My understanding is that when interpreting import tkinter, the current directory is one of the first places Python will look for a package (though that understanding is difficult to verify from the "Searching" portion of the docs). If true, then what's imported by the import tkinter line of cpython/Lib/tkinter/ttk.py is the folder cpython/Lib/tkinter/ itself.
Since the file cpython/Lib/tkinter/ttk.py is the only place where a Widget class is defined in this directory (at least as far as I can tell from the GitHub search function), then it appears that the code in cpython/Lib/tkinter/ttk.py
28 import tkinter
...
512 class Widget(tkinter.Widget):
"""Base class for Tk themed widgets."""
defines a class that extends itself.
Surely there's something I don't understand. What is going on here?
ttk.Widgetextendstkinter.Widgetand you can also create ownclass Widgetwhich can extendtkinter.Widget(class Widget(tkinter.Widget)) orttk.Widget(class Widget(ttk.Widget)) or not use any of them (class Widget())ttkmodule. That said, you're not technically incorrect, but this is part of the standard library.