'modal dialogs' with Tkinter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean McIlroy

    #1

    'modal dialogs' with Tkinter

    I'd like to have a function f such that, when f is invoked, a Tk
    window w is presented in which a number of variables can be modified,
    and f returns the values that are indicated by the relevant
    menus/checkbuttons/etc at the time w gets closed. I've tried various
    ways of doing this, without success. Any assistance would be greatly
    appreciated.

    Peace,
    Sean McIlroy
  • Eric Brunel

    #2
    Re: 'modal dialogs' with Tkinter

    On 22 Feb 2005 06:03:14 -0800, Sean McIlroy <sean_mcilroy@y ahoo.com> wrote:
    [color=blue]
    > I'd like to have a function f such that, when f is invoked, a Tk
    > window w is presented in which a number of variables can be modified,
    > and f returns the values that are indicated by the relevant
    > menus/checkbuttons/etc at the time w gets closed. I've tried various
    > ways of doing this, without success. Any assistance would be greatly
    > appreciated.[/color]

    Here are the necessary ritual incantations to create a modal dialog with Tkinter:

    dlg = Toplevel()
    # ... build the window ...
    ## Set the focus on dialog window (needed on Windows)
    dlg.focus_set()
    ## Make sure events only go to our dialog
    dlg.grab_set()
    ## Make sure dialog stays on top of its parent window (if needed)
    dlg.transient(p arentWdw)
    ## Display the window and wait for it to close
    dlg.wait_window (dlg)

    The callbacks for your "OK", "Cancel" or whatever buttons you want to use should then call dlg.destroy(). This will terminate the wait_window call and continue the execution of the code after it.

    HTH
    - Eric Brunel -

    Comment

    • Fredrik Lundh

      #3
      Re: 'modal dialogs' with Tkinter

      Sean McIlroy wrote:
      [color=blue]
      > I'd like to have a function f such that, when f is invoked, a Tk
      > window w is presented in which a number of variables can be modified,
      > and f returns the values that are indicated by the relevant
      > menus/checkbuttons/etc at the time w gets closed. I've tried various
      > ways of doing this, without success. Any assistance would be greatly
      > appreciated.[/color]

      does the approach described here work for you?

      http://www.pythonware.com/library/tk...og-windows.htm

      (note that the tkSimpleDialog module is included in Python's standard library)

      if it doesn't work, what doesn't work as required/expected?

      </F>



      Comment

      • Birdman

        #4
        Re: 'modal dialogs' with Tkinter

        You could try using: EasyGUI http://www.ferg.org/easygui/

        EasyGUI is different from other GUIs in that EasyGUI is NOT
        event-driven. It allows you to program in a traditional linear fashion,
        and to put up dialogs for simple input and output when you need to. If
        you have not yet learned the event-driven paradigm for GUI programming,
        EasyGUI will allow you to be productive with very basic tasks
        immediately. Later, if you wish to make the transition to an
        event-driven GUI paradigm, you can do so with a more powerful GUI
        package such as anygui, PythonCard, Tkinter, wxPython, etc.

        It works for me and is easy to modify to your needs.

        Comment

        Working...