TkMessageBox - No Module

76,850

Solution 1

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

Solution 2

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 3

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 4

for python 3.x

import tkinter

import tkinter.messagebox

Share:
76,850
Tom Lowbridge
Author by

Tom Lowbridge

Updated on June 21, 2021

Comments

  • Tom Lowbridge
    Tom Lowbridge almost 3 years
    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?

  • s2t2
    s2t2 almost 5 years
    ... so you can invoke like: tkinter.messagebox.showinfo("Congratulations", "You won!")
  • Admin
    Admin almost 4 years
    Care to explain your action? stackoverflow.com/questions/61939967/…
  • Billal Begueradj
    Billal Begueradj almost 4 years
    Sorry, I had to read your question more carefully. I voted to re-open your post and I upvoted it @Trey
  • Roim
    Roim almost 4 years
    Welcome to stackoverflow. Thanks you for your contribution, but please provide further explanations on your solution: don't just give a fix, explain what it does and what was wrong