Ondrej Sika

Dialog Box in Tkinter, Python

28 Dec 2013

import tkMessageBox

Alert

Info
tkMessageBox.showinfo("Window title", "info msg content")
Warning
tkMessageBox.showwarning("Window title", "warning msg content")
Error
tkMessageBox.showwarning("Window title", "error msg content")

Ask

Yes, No
if tkMessageBox.askyesno("Window title", "msg content"):
    print "yes"
else:
    print "no"
Yes, No, Cancel
status = tkMessageBox.askyesnocancel("Window title", "msg content")
if status == True:
    print "yes"
elif == False:
    print "no"
else:
    print "cancel"
Ok, Cancel
if tkMessageBox.askokcancel("Window title", "msg content"):
    print "ok"
else:
    print "cancel"
Retry, Cancel
if tkMessageBox.askretrycancel("Window title", "msg content"):
    print "retry"
else:
    print "cancel"

Input

import tkSimpleDialog
Int
i = tkSimpleDialog.askinteger("Window title", "msg content")
Float
f = tkSimpleDialog.askfloat("Window title", "msg content")
String
s = tkSimpleDialog.askstring("Window title", "msg content")

Source: http://effbot.org/tkinterbook/tkinter-standard-dialogs.htm

Share on Facebook, Twitter, Google+, Linkedin

comments powered by Disqus

--