Tkinter problem

Chad Netzer cnetzer at
Mon Jun 23 01:34:26 CEST 2003

On Sun, 2003-06-22 at 07:02, Eirik wrote:

> What does the "if __name__=='__main__':" mean? I do not fully understand
> this example.

For the example I gave, you can ignore it (and remove the indenting
below).  But it is used in cases where you want to be able to import a
script (to get at its function definitions), as well as run it as a

Basically, when you run a script, the __name__ global is equal to
'__main__', so the example doesn't execute those lines if you import the
script.  It is a common idiom.

Here is the example just as a straightforward script.  Let me know if it
makes the issue you asked about (setting up the proper callback) more

import sys
from Tkinter import *

def my_test_callback():
    global root

root = Tk()
root.t = StringVar()

root.l1 = Label(root, textvariable = root.t)
root.b1 = Button(root, text = "Button", command = my_test_callback)
root.bE = Button(root, text = "End", command = sys.exit)



Chad Netzer <cnetzer at>

More information about the Python-list mailing list