Mailing List Archive

Interactive use of Tk
I'm trying to debug a tkinter application I have using the interactive
prompt via XEmacs. The program runs fine first time around but when run
again (without exiting the interactive prompt) it complains that the
application has been destroyed. How to I stop the application from being
destroyed?

Secondly, has anyone managed to get tkinter windows running whilst still
being able to use the interactive prompt (e.g. by starting the mainloop
in a separate thread). I guess its possible and its just the dodgy
Solaris threads libraries we have installed here that stop it working
for (the jpython examples also cause the command prompt to block for
me).



Cheers,

Stuart

PS. The code which won't run twice:

-----
if __name__ == '__main__':


from Tkinter import *
frame = Frame()
... some other code here ...
Pack.config(frame)
frame.mainloop()

-------


#Works fine:
>>> ## working on region in file /usr/tmp/python1f5be_...
>>>
#Run again:
>>> ## working on region in file /usr/tmp/pythonh2FQL_...
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "/usr/tmp/pythonh2FQL_", line 117, in ?
frame = Frame()
File
"/bham/ums/common/pd/packages/Python/lib/python1.5/lib-tk/Tkinter.py",
line 1406, in __init__
Widget.__init__(self, master, 'frame', cnf, {}, extra)
File
"/bham/ums/common/pd/packages/Python/lib/python1.5/lib-tk/Tkinter.py",
line 1084, in __init__
self.tk.call(
TclError: can't invoke "frame" command: application has been destroyed
Interactive use of Tk [ In reply to ]
Stuart Reynolds wrote:

> I'm trying to debug a tkinter application I have using the interactive
> prompt via XEmacs. The program runs fine first time around but when run
> again (without exiting the interactive prompt) it complains that the
> application has been destroyed. How to I stop the application from being
> destroyed?
>
> Secondly, has anyone managed to get tkinter windows running whilst still
> being able to use the interactive prompt (e.g. by starting the mainloop
> in a separate thread). I guess its possible and its just the dodgy
> Solaris threads libraries we have installed here that stop it working
> for (the jpython examples also cause the command prompt to block for
> me).
>
> Cheers,
>
> Stuart
>
> PS. The code which won't run twice:
>
> -----
> if __name__ == '__main__':
>
> from Tkinter import *
> frame = Frame()
> ... some other code here ...
> Pack.config(frame)
> frame.mainloop()
>
> -------
>
> #Works fine:
> >>> ## working on region in file /usr/tmp/python1f5be_...
> >>>
> #Run again:
> >>> ## working on region in file /usr/tmp/pythonh2FQL_...
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> File "/usr/tmp/pythonh2FQL_", line 117, in ?
> frame = Frame()
> File
> "/bham/ums/common/pd/packages/Python/lib/python1.5/lib-tk/Tkinter.py",
> line 1406, in __init__
> Widget.__init__(self, master, 'frame', cnf, {}, extra)
> File
> "/bham/ums/common/pd/packages/Python/lib/python1.5/lib-tk/Tkinter.py",
> line 1084, in __init__
> self.tk.call(
> TclError: can't invoke "frame" command: application has been destroyed

class MyToplevel(Tix.Toplevel):
def __init__(self):
Tix.Toplevel.__init__(self)
self.tk.call('load', '', 'Tix')
self.bind("<Alt-x>", self.destroy)
self.bind("<Control-x>", self.destroy)
self.tk.call('wm','withdraw','.')

def destroy(self, *args):
self.withdraw()
Tix.Toplevel.destroy(self)
self.quit()

Either replace Tix with Tkinter (I didn't try it with vanilla Tkinter,
though), or go to my Starship site and pick up a fixed version of PyTix (it
seems non-maintained so you may consider me as a vice-maintainer :-):

ftp://starship.python.net/pub/crew/avv/PyTix/

Alexander
Interactive use of Tk [ In reply to ]
Thanks Alexander. I've been suffering from this problem for a while.
But now I have a similar problem with Pmw. Here's a tiny class that
displays the problem (and not much else).

###
from Tkinter import *
import Pmw

class no_graph (Tk):
def __init__ (self):
Tk.__init__ (self)
Pmw.initialise (self)
self.graph = Pmw.Blt.Graph (self, title = "No Data")
self.graph.pack ()

button = Button (self, text = "Quit", command = self.destroy)
button.pack ()

def destroy (self):
self.withdraw ()
Tk.destroy (self)
self.quit ()
###

Interactively, the second time I call no_graph (), I get:

Traceback (innermost last):
File "<stdin>", line 1, in ?
File "no_data.py", line 8, in __init__
self.graph = Pmw.Blt.Graph (self, title = "No Data")
File "/usr/local/lib/python1.5/site-packages/Pmw/Pmw_0_8/lib/PmwBlt.py", line 215, in __init__
Tkinter.Widget.__init__(self, master, _graphCommand, cnf, kw)
File "/usr/local/lib/python1.5/lib-tk/Tkinter.py", line 1084, in __init__
self.tk.call(
TclError: invalid command name "::blt::graph"

I'm guessing I have to quit Pmw before I reinitialize, but I don't
know how. Does anyone know of a good online reference for Pmw or Blt?
Thanks.

--
Sam Varner
SEL 2210 (MC 111)
Department of Chemistry
University of Illinois at Chicago