importing
Ian Kelly
ian.g.kelly at gmail.com
Mon Mar 7 11:02:33 EST 2016
On Mon, Mar 7, 2016 at 8:54 AM, Tony van der Hoff <tony at vanderhoff.org> wrote:
> I thought I understood this, but apparently not:
> Under py3:
>
> 1. "import tkinter" imports the whole module into the name space. Any access
> to names therein must be prefixed with the module name.
> ie top = tkinter.Tk()
> But tkinter.messagebox.showwarning() errors with "module has no attribute
> 'messagebox'"
tkinter.messagebox is a module inside the tkinter package. Importing
tkinter doesn't automatically import tkinter.messagebox also.
>
> 2. "from tkinter import *" loads the name space from the module into the
> program name space. No need to prefix the module name onto the attribute
> name. Pollutes the name space, but makes typing easier.
> ie top = Tk()
> But messagebox.showwarning() still errors.
This is still just loading names from the tkinter module, not its submodules.
> 3. in either of the above cases, if I add "from tkinter import messagebox,
> the attribute resolves correctly.
This is the first place where you actually instruct Python to import
tkinter.messagebox.
More information about the Python-list
mailing list