Tkinter: how to create (modal) dialogs a la tk_dialog?
Peter Otten
__peter__ at web.de
Wed Oct 27 11:57:12 EDT 2010
Olaf Dietrich wrote:
> 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
More information about the Python-list
mailing list