When importing tkinter's "messagebox" module, does the "import tkinter.messagebox" syntax not work? When importing tkinter's "messagebox" module, does the "import tkinter.messagebox" syntax not work? tkinter tkinter

When importing tkinter's "messagebox" module, does the "import tkinter.messagebox" syntax not work?


Importing tkinter.messagebox does work (at least in should, and does in 3.4, maybe there might be a bug in other releases), but it is imported as tkinter.messagebox, which is tedious and lengthy to write, and if the rest of tkinter is being used, it is pointless to do, seeing as tkinter.messagebox will have already been indirectly imported. So generally from tkinter import messagebox is considered easier, and does not loose much, if any readability.


messagebox, along with some other modules like filedialog, does not automatically get imported when you import tkinter. Import it explicitly, using as and/or from as desired. check below 3 examples for better clarification-

    >>> import tkinter    >>> tkinter.messagebox.showinfo(message='hi')Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'messagebox'

.

    >>> import tkinter.messagebox    >>> tkinter.messagebox.showinfo(message='hi')'ok'

.

 >>> from tkinter import messagebox    >>> messagebox.showinfo(message='hi')'ok'