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

Richard Damon Richard at Damon-Family.org
Fri Aug 28 17:22:37 EDT 2020


On 8/28/20 4:38 PM, boB Stepp wrote:
> On Fri, Aug 28, 2020 at 2:48 AM Alan Gauld via Tutor <tutor at python.org> wrote:
>> On 28/08/2020 02:34, boB Stepp wrote:
>>
>>> 3.8.3:  import tkinter as tk
>>> 3.8.3:  window = tk.Tk()
>>>
>>> A tkinter window opens despite there being no explicit call to
>>> window.mainloop().  Why is this so?
>> Because it's what Tcl/Tk does...
> Perhaps I should phrase the question differently:  Why does this
> happen in the interpreter but does *not* happen if I run a program
> without calling window.mainloop()?
>
Because Python when in interactive mode uses tkinter, and has a main
loop of it own that will pump your messages if you don't.

-- 
Richard Damon



More information about the Tutor mailing list