python logo

tkinter messagebox

Python hosting: Host, run, and code Python in the cloud!

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

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()

# 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

If you are new to programming Tkinter, I highly recommend this course.

download tkinter examples


Leave a Reply: