Reading about Python? Actually practice it. Try PyChallenge free

Python Tutorial

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

Tkinter Message box TkMessage boxTo show a minimalistic Tkinter message box, use the function showinfo() where the parameters are the window title and text.

The 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

tkinter-dialog Tk messagebox dialog

Tkinter 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

BackNext