Problems using tkSimpleDialog

Eric Brunel eric.brunel at pragmadev.com
Tue Dec 11 11:22:06 EST 2001


Hi Simon,

The problem is simple: Tk needs to be initialized before the
"tkSimpleDialog" module can work. Just do:
import Tkinter
root = Tkinter.Tk()
before calling tkSimpleDialog.askstring, and it will magically solve the
problem.

What happens is that if you don't explicitely set the "parent" option for
your dialog, a default one is chosen which is "the" instance of the Tk class
for your application, corresponding to its main window. Apparently, if this
instance was not created "manually", the "tkSimpleDialog" module does not
create one automatically.

Hope this helps.
 - eric -

"Simon Brunning" <simon at brunningonline.net> a écrit dans le message news:
314b29e9.0112110704.1b42edd4 at posting.google.com...
> I an having trouble with this module. I'm running Python 2.1 on Win NT
> 4.
>
> Here is what I am doing:
>
> Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on
> win32
> Type "copyright", "credits" or "license" for more information.
> >>> import tkSimpleDialog
> >>> tkSimpleDialog.askstring('Title in here', 'Prompt here')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "D:\dev\python\lib\lib-tk\tkSimpleDialog.py", line 287, in
> askstring
>     d = apply(_QueryString, (title, prompt), kw)
>   File "D:\dev\python\lib\lib-tk\tkSimpleDialog.py", line 177, in
> __init__
>     Dialog.__init__(self, parent, title)
>   File "D:\dev\python\lib\lib-tk\tkSimpleDialog.py", line 71, in
> __init__
>     self.geometry("+%d+%d" % (parent.winfo_rootx()+50,
> AttributeError: 'None' object has no attribute 'winfo_rootx'
> >>>
>
> Interestingly, I *do* see the required dialog here, along with an
> empty window titled 'tk'. Entering anything into the dialog gets me:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "D:\dev\python\lib\lib-tk\Tkinter.py", line 1285, in __call__
>     return apply(self.func, args)
>   File "D:\dev\python\lib\lib-tk\tkSimpleDialog.py", line 127, in ok
>     self.cancel()
>   File "D:\dev\python\lib\lib-tk\tkSimpleDialog.py", line 132, in
> cancel
>     self.parent.focus_set()
> AttributeError: 'None' object has no attribute 'focus_set'
>
> What am I doing wrong?
>
> Cheers,
> Simon B.





More information about the Python-list mailing list