Tkinter dying a Flailing Death?

anders schneiderman aschneiderman at njdc.com
Fri Mar 31 09:09:18 EST 2000


I've been working for a while on a Tkinter program, and almost every time I
quit it, it twice complains that "This program has performed an illegal
operation and will be shut down."  

Since I'm new to Python, I figured it must be something I was doing.  So, I
tried running a demo from the Tkinter library, Dialog.py.  Surprise!  It
also dies twice, bitterly complaining about illegal operations.  The code
below is the Tkinter demo.  Any idea why it's so unhappy when it quits?

Thanks,
Anders Schneiderman
National Journal Daily Briefings Group

P.S.  I've got 8.0.5 Tcl and Python 1.5.2 and I'm running Win95.




----------------------------------------------------------------
# Dialog.py -- Tkinter interface to the tk_dialog script.

from Tkinter import *
from Tkinter import _cnfmerge

if TkVersion <= 3.6:
	DIALOG_ICON = 'warning'
else:
	DIALOG_ICON = 'questhead'


class Dialog(Widget):
	def __init__(self, master=None, cnf={}, **kw):
		cnf = _cnfmerge((cnf, kw))
		self.widgetName = '__dialog__'
		Widget._setup(self, master, cnf)
		self.num = self.tk.getint(
			apply(self.tk.call,
			      ('tk_dialog', self._w,
			       cnf['title'], cnf['text'], 
			       cnf['bitmap'], cnf['default'])
			      + cnf['strings']))
		try: Widget.destroy(self)
		except TclError: pass
	def destroy(self): pass

def _test():
	d = Dialog(None, {'title': 'File Modified',
			  'text':
			  'File "Python.h" has been modified'
			  ' since the last time it was saved.'
			  ' Do you want to save it before'
			  ' exiting the application.',
			  'bitmap': DIALOG_ICON,
			  'default': 0,
			  'strings': ('Save File', 
				      'Discard Changes', 
				      'Return to Editor')})
	print d.num


if __name__ == '__main__':
	t = Button(None, {'text': 'Test',
			  'command': _test,
			  Pack: {}})
	q = Button(None, {'text': 'Quit',
			  'command': t.quit,
			  Pack: {}})
	t.mainloop()





More information about the Python-list mailing list