[Tutor] Why does "window = tk.Tk()" open a tkinter window when typed in the Python interpreter?
Alan Gauld
alan.gauld at yahoo.co.uk
Sat Aug 29 06:27:54 EDT 2020
On 29/08/2020 09:13, Peter Otten wrote:
> indicates that the behaviour you observe is implemented in CPython.
> 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.
How interesting. Which makes me wonder what exactly the mainloop()
function does extra? I tried it in the interpreter and sure enough
it seems to work as expected but when you call mainloop() it
stops reading input at the Python prompt. But the Tkinter GUI
works with or without mainloop() which I didn't expect.
Definitely worth some more digging.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list