[Tutor] Why does "window = tk.Tk()" open a tkinter window when typed in the Python interpreter?

boB Stepp robertvstepp at gmail.com
Sat Aug 29 12:58:00 EDT 2020


On Sat, Aug 29, 2020 at 3:14 AM Peter Otten <__peter__ at web.de> wrote:
>
> boB Stepp wrote:
>
> > On Fri, Aug 28, 2020 at 5:55 PM Alan Gauld via Tutor <tutor at python.org>
> > wrote:

> >> This may require some examination of the source.
> >
> > Are you inclined to think the source code of Tcl/Tk is where to look,
> > or do you think it is how Python's wrapper, tkinter,  implements
> > Tcl/Tk is where I should look?  I've been trying to research this
> > online and have been unsuccessful so far -- not quite sure how to
> > phrase an effective set of search terms.  I did come across that the
> > scripting language, Tcl, seems to have its own interpreter mode, so
> > your initial comments may be spot on if this was the behavior being
> > sought up front by Tcl itself.
>
> The following comment in Modules/_tkinter.c
>
> /* If Tcl can wait for a Unix file descriptor, define the EventHook()
> routine
>    which uses this to handle Tcl events while the user is typing commands.
> */
>
> indicates that the behaviour you observe is implemented in CPython.

Ah!  Thanks, Peter!

> When you run a script like
>
> import tkinter as tk
> root = tk.Tk()
> button = tk.Button(root, text="Press", command=lambda: print("pressed"))
> button.pack()
> input()
>
> you'll see that it's not just the look (pressing the button will work like
> expected) and that it's not limited to the interpreter.

This gets even more interesting -- and potentially useful.  Again,
thanks again, Peter.



-- 
boB


More information about the Tutor mailing list