'modal dialogs' with Tkinter

S

Sean McIlroy

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
 
E

Eric Brunel

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.

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(parentWdw)
## 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 -
 
F

Fredrik Lundh

Sean said:
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.

does the approach described here work for you?

http://www.pythonware.com/library/tkinter/introduction/dialog-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>
 
B

Birdman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top