When importing the "messagebox" tkinter module, the "import tkinter.messagebox" syntax doesn't work?

Since "messagebox" is a module in the "tkinter" package, why do I need to use

from tkinter import messagebox

      

instead

import tkinter.messagebox

      

I was under the impression that I would have to use the following syntax to import a module inside a package:

import package_name.module_name 

      

Thank you for your help.

+3


source to share


1 answer


Importing tkinter.messagebox does work (at least it should and should be in version 3.4, maybe there might be a bug in other versions), but it is imported as tkinter.messagebox

, which is tedious and time consuming to write, and if the rest is tkinter

used it is pointless do as it is tkinter.messagebox

already imported indirectly. Thus, it from tkinter import messagebox

is usually considered to be lighter and not much lost if there is readability.



+1


source







All Articles