[Tutor] Is this me or is it something odd in tkInter?

David Maclagan david@verso.org
Sun, 10 Sep 2000 11:34:14 +1000


I'm trying to use some of the prepackaged dialogs that tkinter comes 
with, specifically askopenfile in tkFileDialog.py, and get the following 
error:
_____________________
Traceback (innermost last):
  File "C:\PROGRA~1\PYTHON\TOOLS\IDLE\ScriptBinding.py", line 
131, in run_module_event
    execfile(filename, mod.__dict__)
  File "C:/Program Files/Python/tests/toygui2.py", line 12, in ?
    filemenu.add_command(label="Open", command = openfile())
  File "C:/Program Files/Python/tests/toygui2.py", line 7, in openfile
    filename = tkFileDialog.askopenfilename()
  File "C:\Program Files\Python\Lib\lib-tk\tkFileDialog.py", line 74, in 
askopenfilename
    return apply(Open, (), options).show()
  File "C:\Program Files\Python\Lib\lib-tk\tkCommonDialog.py", line 
49, in show
    w = Frame(self.master)
  File "C:\Program Files\Python\Lib\lib-tk\Tkinter.py", line 1406, in 
__init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "C:\Program Files\Python\Lib\lib-tk\Tkinter.py", line 1084, in 
__init__
    self.tk.call(
TclError: can't invoke "frame" command:  application has been 
destroyed
-------------------

The program that's generating this is:
(well, okay, there was originally more to it, but I hacked it back to 
the smallest I could, and still got the same problem.)

-----------
from Tkinter import *
import tkFileDialog

root=Tk()

def openfile():
    filename = tkFileDialog.askopenfilename()

menubar = Menu(root)

filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command = openfile())
# display the menu
root.config(menu=menubar)

frame = Frame(root)

frame.pack()

root.mainloop()
--------------------

Am I making a (or some) fundamental error(s)?

I'm using IDLE 0.4, and python 1.5.2 on a win98 system

David



-------
David Maclagan
David@verso.org