tkMessageBox returns 'can't invoke "frame" command:' error

Michael P. Reilly arcege at
Thu Jun 24 14:05:51 EDT 1999

Fredrik Lundh <fredrik at> wrote:
: tlng at wrote:
:> If I import my script above for the first time, my script runs fine.
:> However, after I quit my script and try to reload my script at the
:> Python interpreter by typing reload(myscriptname), I get the error
:> message: "TclError: Can't invoke "frame" command:". Actually, it is
:> quite a long-winded error message, I'm just giving the last line.

: you could try passing the root window to askyesno, like
: this:

: reply = tkMessageBox.askyesno("foo", "bar!", master=rootWindow)

: no guarantees, though.

:> > The actuall error is caused by the Tk mainloop cannot be restarted,
:> > obviously Tkinter was never designed to support what you're doing
:> > here.
:> Oh, you mean I can't reload my script if my script contains Tkinter
:> calls? How do you test your Tkinter scripts then?

: well, dejanews has the answer, as usual:

:>    "Incidently, in a recent project, we successfully used a combination of
:>    random generators, chimps, and 3-year olds to produce the actual code
:>    base, while the engineers concentrated their efforts on testing."

: (since then, all the engineers have quit. go figure...)

:> What I usually do is, I write my Python script in a text editor, switch
:> to the Python interpreter and reload my script to see if my script is
:> working. Since I can't do this with Tkinter scripts, does that mean
:> everytime I want to retest my Tkinter scripts, I have to quit Python
:> and restart Python?

: I usually type ctrl-C twice to test my code.  maybe you
: could train your editor to do something similar for you?

:> > The cause of your problem seems be partly that you actually
:> > expected this to work, putting lots of code in a module
:> > initialisation is not good style.
:> That bit about "putting lots of code in a module initialisation" just
:> went over my head. What did I do that constitutes "module
:> initialisation"? I've reposted my sample script below so you can point
:> it out to me easily.

: code that's not in a def or a class are executed when you
: run your program as a script, *and* if you import your pro-
: gram as a module.  it's usually better to put the important
: stuff in a function instead, by various reasons (it runs faster,
: it's easier to deal with the day you decide to turn your code
: into a module, etc, etc).

: </F>

I haven't been following this thread too closely, but in general, I
believe that as long as you call the "quit" method of any Tkinter
widget, then "mainloop()" is restartable.  (Having just redesigned the
underlying Tcl/Tk/Tkinter modules, I've seen how this works.)  If you
instead call the "destroy" method, then it is unlikely that you can
restart the event loop (the Tk object has usually been destroyed, but
not always).


More information about the Python-list mailing list