TkInter message box
The Tkinter tkMessageBox has various methods to display a message box.
There is a slight difference between Tkinter for Python 2.7 and Python 3. To find your Python version try one of these commands:
python --version
python3 --version
Related courses
Practice Python with interactive exercises
Tkinter Message box
TkMessage boxThe showinfo() function is in a different module depending on the Python version.
Python 3.x
from tkinter import messagebox
messagebox.showinfo("Title", "a Tk MessageBox")
Python 2.7
import Tkinter
import tkMessageBox
tkMessageBox.showinfo("Title", "a Tk MessageBox")
Tkinter showerror, showwarning and showinfo
Tk messagebox dialogTkinter includes several other message boxes:
- showerror()
- showwarning()
- showinfo()
Python 3.x
import tkinter
from tkinter import messagebox
# hide main window
root = tkinter.Tk()
root.withdraw()
# message box display
messagebox.showerror("Error", "Error message")
messagebox.showwarning("Warning","Warning message")
messagebox.showinfo("Information","Informative message")
Python 2.7
import Tkinter
import tkMessageBox
# An error box
tkMessageBox.showerror("Error","No disk space left on device")
# A warning box
tkMessageBox.showwarning("Warning","Could not start service")
# An information box
tkMessageBox.showinfo("Information","Created in Python.")
You may like: Tkinter Question Dialog or More Tkinter