Tkinter: how to create (modal) dialogs a la tk_dialog?

O

Olaf Dietrich

I'm stuck with a probably simple task: How can I create
a user defined dialog (similar to tkFileDialog.askdirectory(),
but with my own set of options/selections)?

In Tk, that's

set reply [tk_dialog .foo "The Title" "Which one?" {} 0 \
Yes No "I'm not sure"]

What would be the equivalent with Tkinter?


And it would be even nicer to have a dialog with a
listbox-lie selection instead of separate buttons
for each choice? How could that be done?


Thanks for any suggestions!

Olaf
 
P

Peter Otten

Olaf said:
I'm stuck with a probably simple task: How can I create
a user defined dialog (similar to tkFileDialog.askdirectory(),
but with my own set of options/selections)?

Have a look at the SimpleDialog module. A usage example is at the end of the
file:

$ grep __main__ /usr/lib/python2.6/lib-tk/SimpleDialog.py -A1000
if __name__ == '__main__':

def test():
root = Tk()
def doit(root=root):
d = SimpleDialog(root,
text="This is a test dialog. "
"Would this have been an actual dialog, "
"the buttons below would have been glowing "
"in soft pink light.\n"
"Do you believe this?",
buttons=["Yes", "No", "Cancel"],
default=0,
cancel=2,
title="Test Dialog")
print d.go()
t = Button(root, text='Test', command=doit)
t.pack()
q = Button(root, text='Quit', command=t.quit)
q.pack()
t.mainloop()

test()

You can invoke it with

$ python -m SimpleDialog

Peter
 
O

Olaf Dietrich

Peter Otten said:
Have a look at the SimpleDialog module. A usage example is at the end of the
file:

Thanks, that's sufficiently close to what I was looking
for (in particular after changing the layout to vertically
packed buttons). Could it be that these parts of Tkinter
are not particularly extensively documented? (Or am I searching
with the wrong expressions?)

Is there also any "template" dialog that works with a listbox
instead of buttons (or is more similar to the file dialogs)?

Thanks,
Olaf
 
A

Andrew

Could it be that these parts of Tkinter
are not particularly extensively documented? (Or am I searching
with the wrong expressions?)
Olaf

I've wondered about this too. The tkinter and tkinter.ttk sections of the
documentation seem to have a large number of classes and functions listed
as part of the module but without any more than a line or two about what
they do or how to use them. The last (and only, so far) time I used
tkinter, I often found it more useful to examine Tk documentation to
discover, say, what options or arguments were possible and/or useful, and
then try to translate that into the python/tkinter equivelant.
 
P

python

Excellent Tkinter tutorials

Fundamentals Of Tkinter Part 1
http://www.dreamincode.net/forums/topic/116314-fundamentals-of-tkinter-part-one/

Fundamentals Of Tkinter Part 2
http://www.dreamincode.net/forums/topic/117474-fundementals-of-tkinter-part-2/

Tkinter, Part 3 - Dialogs
http://www.dreamincode.net/forums/topic/135050-tkinter-part-3-dialogs/

Tkinter, Part 4 - Basic Event Bindings
http://www.dreamincode.net/forums/topic/137447-tkinter-part-4-basic-event-bindings/

....

Excellent Tkinter documentation

List of Python Tkinter documentation
http://wiki.python.org/moin/TkInter

Overview
http://docs.python.org/library/tkinter.html

Full documentation
http://effbot.org/tkinterbook/

....

If you're using Python 2.7/3.1 check out the new ttk (Tile) support for
sexy, native looking user interfaces based on Tkinter (really!)

http://www.tkdocs.com/tutorial/onepage.html

Regards,
Malcolm
 

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,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top