[Tutor] Tk help

Kirk Vander Meulen kvander11 at gmail.com
Mon Jan 11 17:15:02 CET 2010


Hi Alan, thanks for the reply and my apologies for not realizing there was a
Tkinter-discuss group.  After even more searching, this seems to be
something weird with my version of Tkinter and/or my installation.  I can
eliminate this effect on my machine (linux, python 2.6) by explicitly
creating and destroying a toplevel window after the askdirectory() dialog,
as such:

import tkFileDialog,tkMessageBox
import Tkinter
toplevel=Tkinter.Tk()
addDirectory=tkMessageBox.askyesno('a dialog','Add a directory?')
print addDirectory
theDirectory=tkFileDialog.askdirectory()
toplevel.destroy()
addDirectory=tkMessageBox.askyesno('a dialog','Add a directory?')
print addDirectory

If I remove the "toplevel.destroy()" call, I get incorrect behavior.
However, if I run the same program on my windows installation (python 2.5),
I get correct behavior regardless of the presence of this destroy() command,
which I'm pretty sure must be the expected behavior.  I will look into my
tkinter version and file a bug report if I convince myself my install's not
goofy- I get the same behavior with my 3.1 installation on my linux box.

Regarding teh print statements, I was using python 3 syntax but running
python 2.6...I just like the 3 syntax better, sorry for the confusion.  The
extra prints were just me getting carried away with debugging, I love
printing stuff.

Kirk


> "Kirk Vander Meulen" <kvander11 at gmail.com> wrote
>
> > I'm working on a program partly to get the hang of gui programming.  I'm
> > a
> > bit puzzled by the behavior of simple dialogs- I wonder why, in the
> > following code, the second call to tkMessageBox.askyesno always returns
> > 'False' (either 'yes' or 'no' return False!).  If I take out the call to
> > tkFileDialog.askdirectory(), the second call works as expected
> > (yes->True,no->False).  I would really appreciate if someone could take a
> > look at this and tell me what I'm missing.  Thanks,
>
> After converting the imports for Python 3 it worked perfectly for me
>
> >>> ================================ RESTART
> >>> ================================
> >>>
> True
> True
> H:/PROJECTS/Python/Tutor3
> True
> H:/PROJECTS/Python/Tutor3
> >>> ================================ RESTART
> >>> ================================
> >>>
>
> > import tkFileDialog,tkMessageBox
> > addDirectory=tkMessageBox.askyesno('a dialog','Add a directory?')
> > print(addDirectory)
> > theDirectory=tkFileDialog.askdirectory()
> > print(addDirectory)
>
> Any reason why you print it a second time even though there has been no
> change?
>
> > print(theDirectory)
> > addDirectory=tkMessageBox.askyesno('a dialog','Add a directory?')
> > print(addDirectory)
> > print(theDirectory)
>
> And the same here?
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100111/7d8cde79/attachment.htm>


More information about the Tutor mailing list