python - i need to know whats the diference between from tkinter import * and from tkinter import 'module' -


i learnig python beginning, doing tutorials , video-tutorials. using sublime text 3 wrinting code , console of sublimerepl run files , code. few days ago had search on web how make sublimerepl run idle 3 runs, , made it.

the problem right in lesson doing right teaching me how use tkinter in videos guy codes:

from tkinter import * colorchooser.askcolor() 

and works, when code , doesn't work. error says:

traceback (most recent call last): file "", line 1, in nameerror: name 'colorchooser' not defined

i need code :

from tkinter import colorchooser colorchooser.askcolor() 

and works.

i need know why have this?, , why doesn't work me in first way?

i not english speaker tried best.

with

from tkinter import colorchooser 

you importing (sub-)module colorchooser (plus variables , functions) package (which structured module) tkinter.

packages way of structuring python’s module namespace using “dotted module names”.

so module tkinter structured follows:

tkinter/     colorchooser/         askcolor()         ... 

with from tkinter import * importing methods , variables tkinter (in fact public objects not starting _), but not submodules, why 2 methods not same:

... statement from sound.effects import * not import submodules package sound.effects current namespace

(source)

you can, (even though many from ... import * bad practice)

from tkinter.colorchooser import * 

Comments