0
from tkinter import * 
from tkinter import messagebox

can someone please explain why the second line is needed as we've already imported everything from tkinter package? Sorry if this question seems banal,but im trying my best to understand it.

i thought everything would be imported from the first statement and the second statement was not necessary.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
  • This is how `tkinter` as python *module* was built. You can read about [Modules](https://docs.python.org/3/tutorial/modules.html) on python.org – Thingamabobs Apr 29 '23 at 18:42

2 Answers2

0

In most cases importing the main package does the work, but in some specific cases( application dependent) some modules need to be imported seperately. May your code has some specific purpose.

Sky
  • 9
  • 3
0

Importing a package only imports its __init__.py. That file decides whether it should import other modules (internal to the package or external). A package developer may want to always import core functionality, but may skip modules to reduce the cost of your original import. Consider package/alwaysneeded.py and package/hugeobscureandrarelyused.py. That second won't be imported automatically.

tkinter has lots of widgets. Its not surprising that it doesn't pull them all in by default.

tdelaney
  • 73,364
  • 6
  • 83
  • 116