TkMessageBox - No Module

for python 3.x

import tkinter

import tkinter.messagebox


In Python 2.x, to import, you'd say import tkMessageBox. But in Python 3.x, it's been renamed to import tkinter.messagebox.

Hope it helped :))


If you don't want to have to change the code for Python 2 vs Python 3, you can use import as:

try:
    from tkinter import messagebox
except ImportError:
    # Python 2
    import tkMessageBox as messagebox

:edit: However, tkinter is in a separate package in Debian due to Debian policies, so to avoid an incorrect fallback to Python 2 code I now use:

import sys
if sys.version_info.major >= 3:
    from tkinter import messagebox
else:
    import tkMessageBox as messagebox

Then using messagebox as follows will work in either version:

messagebox.showerror("Error", "Message.")

In Python3.x things have changed a little bit:

   >>> import tkinter
   >>> import tkinter.messagebox
   >>>

I mean what we call tkMessageBox in Python2.x becomes tkinter.messagebox in Python3.x