[Tutor] deleting CR within files

Alan Gauld alan.gauld at blueyonder.co.uk
Fri Apr 16 14:16:54 EDT 2004

> root=Tkinter.Tk()
> f=Tkinter.Button(root, text="Find Files",
> x=Tkinter.Button(root, text="Close", command=sys.exit).pack()

Like another recent poster you are assigning the value of pack()
to the variables. But pack returns None. In this case you don't
use f or x so it doesn't matter but could lead to some strange
things if you tried to use them later...

> if f:

Oops, sorry, you do use f, it will be false since pack() returns
none wich is considered as false.

As a result the block of code inside the if never gets executed.

You need to define the widget then pack it:

f=Tkinter.Button(root, text="Find Files", command=dialog.dialog)

The other problem is that oits not clear how you rtrieve the
output from dialog.dialog. I suspect you need to wrap that in
a local function that stores the value for you:

result = 0
def doDialog()
   global result
   result = dialog.dialog()

Now pass doDialog into the command parameter and when the
button is pressed the result will be stored in the global
variable result. [ If you were using objects you would make
the doDialog a method and store the result in an attribute
of the class to avoid using a global variable...]


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list