Am 12.10.16 um 13:18 schrieb ast:
Hello, here is the small program:

from tkinter import *

class Test:
   def __init__(self):
       root = Tk()
       label = Label(root, text="this is a test")


I dont understand why this program works. After execution
of function __init__, local variables 'root' and 'label' should disapear
and the widgets Tk and Label should be garbage collected. But it's not
the case, the window Tk is still on the screen with the label inside it.
Why ?

Because the Test() call does never terminate. You have the mainloop inside of your constructor. As long as this loop runs, your program exists. Try it by putting

print("Now I am here")

and you'll see.


Reply via email to