Problem with a dialog

ast nomail at invalid.com
Thu Dec 11 05:50:50 EST 2014


Hello

I provide two almost identical small test case programs.
The first one works as expected, 'True' is printed on the
console.
With the second one Python complains that 'test' is not 
known. I dont understand why.

Python 3.4, windows


#####################
## First
#####################

from tkinter import *
import tkinter.simpledialog

class MyDialog(tkinter.simpledialog.Dialog):

    def body(self, master):
        print(test)
        
    def apply(self):
        pass

root = Tk()
test = True
setup = MyDialog(root)

# 'True' is printed on the console. Works !


 
#####################
## Second
#####################
 
from tkinter import *
import tkinter.simpledialog

class MyDialog(tkinter.simpledialog.Dialog):

    def body(self, master):
        print(test)
        
    def apply(self):
        pass

def try_():

    test = True 
    setup = MyDialog(root)


root = Tk()
try_()

# NameError: name 'test' is not defined



More information about the Python-list mailing list