Mailing List Archive

TKinter modal dialog
Okay, here's the brief:

File processing task (adds structure to VRML files according to
heuristic rules determined by the user) needs to query the user every
so often if there is a missing/ambiguous rule. I would like to make
this a GUI dialogue using TKinter. I have said dialogue written using
the simpledialog class, and have looked at
http://www.pythonware.com/fredrik/tkdraft/ which suggests I might use
widget.wait_window, however, this doesn't really get the effect I'm
looking for, as it returns control to a widget, whereas I just want
the dialog to exit (and be destroyed) and control to return to the
processing run.

The win32 extension dialogs have a "doModal", which is exactly what
I'm looking for. Anyone care to point out what section of the docs I
didn't read that describes a TKinter doModal :) .

Enjoy,
Mike

______________________________________
M i k e C . F l e t c h e r

mcfletch@vrtelecom.com

Designer, Researcher
TKinter modal dialog [ In reply to ]
Mike C. Fletcher wrote:

> The win32 extension dialogs have a "doModal", which is exactly what
> I'm looking for. Anyone care to point out what section of the docs I
> didn't read that describes a TKinter doModal :) .

I'm using a subclass of Toplevel to do this. However the window will
appear in the Windows Task Bar.

Michael.
--------
Short listing:
--------------
DEFBTN_OK = 0x00000001
DEFBTN_CANCEL = 0x00000002

class aDlgBox (Tkinter.Toplevel):
def __init__( self, parent, title, defBtns):
Tkinter.Toplevel.__init__(self, parent)
self.protocol( 'WM_DELETE_WINDOW', self._setAbort)
self.State = 0
self.title(title)
self.BtnFrame = Tkinter.Frame(self, bd=0)
self.BtnFrame.pack(side='bottom', fill='x', expand=1)
if defBtns & DEFBTN_CANCEL:
self.Cancel = Tkinter.Button(self.BtnFrame, text="Abbrechen",
underline=0, command =
self._setAbort)
self.Cancel.pack(side='right')
if defBtns & DEFBTN_OK:
self.Ok = Tkinter.Button(self.BtnFrame, text="Bestätigen",
underline=0,
command = self._setOk)
self.Ok.pack(side='right')

def AddChild( self, wdg, **kw ):
wdg.pack(kw, after=self.BtnFrame)

def Control( self ):
oldFoc = self.focus_get()
self.focus_set()
self.grab_set()
self.mainloop()
self.grab_release()
if oldFoc:
oldFoc.focus_set()

return self.State

def _setAbort( self ):
self.State = 0
self.quit()

def _setOk( self ):
self.State = 1
self.quit()