Mailing List Archive

Identical callback problems
I've got a GUI that is trying to execute the same callback from two
different events. One is working and the other isn't, even though it's
the same callback.

Basically, it's a program that opens a modal dialog box so that the user
can enter information. When the callback is bound to a button, the
dialog box opens without problems. When the callback is bound to a
double-click, the dialog box STILL opens but I get an error saying
"TclError: grab failed: window not viewable". It's not an invocation
problem since the creation of a DlogBox isn't dependent on anything.
Any idea how I can satisfy tk so that it doesn't complain about this?

To see the bug, run the program below. Double-click on the left side
(error) and then click the button on the right (no error).

=================================================================
from Tkinter import *

# this just pops up a modal dialog box with a button in it
class DlogBox(Toplevel):
def __init__(self):
Toplevel.__init__(self)
f1 = Frame(self)
f1.pack(anchor=N, expand=YES, fill=X)
Button(self, text='OK', command=self.destroy).pack(anchor=S)
self.grab_set() # make myself modal:
self.focus_set() # mouse grab, keyboard focus, wait...
self.wait_window() # till destroy; else returns to caller
now

# The main app
class TestApp(Frame):
def __init__(self,parent=None):
Frame.__init__(self,parent,relief=GROOVE,borderwidth=4)
self.pack(expand=YES, fill=BOTH)
items = Listbox(self)
items.pack(side=LEFT, expand=YES, fill=BOTH)

# bind the button to the callback
button = Button(self,text="Foo",command=self.callback)
button.pack(side=RIGHT,expand=YES, fill=BOTH)

# bind a double-click on the Listbox to the callback
items.bind('<Double-1>', self.callback)

# the callback that exposes the DlogBox
def callback(self,event=None):
print "Callback called with",event
DlogBox()

if __name__ == '__main__':
TestApp().mainloop()


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.