Interactive use of Tk

Alexander V. Voinov avoinov at raima.com
Fri Jul 23 16:46:05 EDT 1999


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






More information about the Python-list mailing list