TKinter modal dialog

Michael S. Schliephake mss at kepler.de
Mon Jun 14 12:33:48 EDT 1999


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()




More information about the Python-list mailing list