'TkMessageBox - No Module

import TkMessageBox

When I import TkMessageBox it displays the messsge 'ImportError: No module named 'TkMessageBox'.

As far as I know im using python 3.3.2 and Tk 8.5.

Am I using the wrong version of python or importing it wrong ?

Any answers would be extremely useful. Alternatively is there something similar in the version i am using?



Solution 1:[1]

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

Then using messagebox as follows will work in either version:

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

Solution 2:[2]

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

Solution 3:[3]

for python 3.x

import tkinter

import tkinter.messagebox

Solution 4:[4]

from tkinter import messagebox sous Python 3 messagebox.showinfo(title=None, message=None, **options)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Hung Truong
Solution 3 Suraj Verma
Solution 4 Diversity infinie YT