Reputation: 899
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?
Upvotes: 44
Views: 98206
Reputation: 1145
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 causing code above to fall back to Python 2 incorrectly. So instead, you should do:
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.")
Upvotes: 11
Reputation: 1
from tkinter import messagebox sous Python 3 messagebox.showinfo(title=None, message=None, **options)
Upvotes: 0
Reputation: 369
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 :))
Upvotes: 8
Reputation: 22724
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
Upvotes: 89