I am still lost in finding official documentation or documentation on a certain thing. You often recommend going to Python docs on this website, but even this documentation may not be official, may not include everything, and may include links to obsolete texts. So for example tkinter in docs.python.org points out “This documentation will concentrate on these additions and changes, and refer to the official Tcl/Tk documentation for details that are unchanged.” Going there I can find links to 20 year old book. Is it still valid? Or I could search in their glossaries or Index, but again, how do I find something specific (in this case method get(), if I don’t know where to look for it (so for example in which section of their indices)? There is no “complete” one-page documentation of Tkinter or Python?
If possible, when you find a documentation problem like this, please file a bug report. External sites change and move around. Those changes aren’t always noticed.
In this case, the official Tcl/Tk docs can be found here.
Edit: I assume by “twenty year old book” I assume you’re referring to Mark Lutz’s book. There might well be newer books (or more recent editions of Mark’s book), but I think the trend is to refer more often to online resources. I’ll open an issue about it.
Unfortunately the Python tkinter documentation assumes the reader is already familiar with Tcl/Tk and only really divulges what is required for an experienced Tcl/Tk user to use it as a wrapper. I found it pretty hard to get my head around at first as one has to figure out how the native Tcl/Tk syntax is converted into tkinters object oriented style.
From memory, it boils down to this (others feel free to correct if I’m wrong): in Tcl/Tk widgets are referenced using their ‘path’, namely a string describing the path one would take down through the widget heirachy in order to reach the referenced widget, starting with the root window (always denoted using a period ‘.’) and ending with the referenced widget.
A path is then followed by a command that operates on the chosen widget, which is then followed by options, etc. Native Tcl/Tk looks, to me anyway, much more like a command line interface you’d use with a shell like BASH.
However, the tkinter way of doing things is to use an object oriented approach. So, Instead of referencing widgets using a path, it provides classes that can be used to create objects that represent Tk widgets; instantiating a widget’s class returns an object that represents an instance of that widget, and also creates the corresponding widget for your GUI application. You then use the methods of that object to operate on the widget.
The key thing to note is that in tkinter, widgets are represented by their object instead of a path, and we operate on them using methods, not commands. This means that you can go to the official Tcl/Tk documentation and look up a command, and there is a good chance that command is implemented in tkinter, either as a method (in the case of commands that operate on widgets) or as a class (in the case of commands that create widgets).
I’m not 100% sure but it sounds like you’ve found your way to the TkDocs tutorial, which is very good and what I used to learn tkinter, but it’s not a reference manual. This is the official Tk reference. It’s a bit of a slog when you’re not used to reading it and coming from the Python side of things, but bear in mind how Tcl/Tk semantics are expressed using tkinter and you can work it out.
Which one? None of the four I see there is that old.
I assumed the OP was referring to Mark Lutz’s book, but that’s only about 12 years old, and the tag line on the cover seems to indicate Python 3 coverage. (Still, Python 3 has a bunch of changes since the early Python 3 days.)
The Ousterhout book (last item) was published in 2009. I wonder if it’s still current.
I am sorry, 23 years old: Python and Tkinter programming.
This links to Python and Tkinter Programming by John Grayson, published in 2000.
But the docs link to:
- Python and Tkinter Programming
By Alan Moore. (ISBN 978-1788835886)
There’s a mistake here. This Moore book is really called Python GUI programming with Tkinter, and was published in 2018. I’ve opened a PR to fix the docs.
Actually they said:
"… refer to the official Tcl/Tk documentation …” Going there I can find links to 20 year old book.
So I think they do mean that very old book, but the link wasn’t on the Python page but somewhere in the Tcl/Tk doc that the Python page links to.
(Using the Tcl/Tk site’s search function to search “tkinter” gives me this page as the top result, which links to that very old book by Grayson.)