On 4/4/2016 11:31 AM, ast wrote:
hello
import tkinter as tk
import tk.ttk as ttk
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import tk.ttk as ttk
ImportError: No module named 'tk'
of course
import tkinter.ttk as ttk
works
Strange, isn't it ?
Nope. As other said, 'import tkinter as tk' imports a module named
'tkinter' and *in the importing modules, and only in the importing
module*, binds the module to 'tk'. It also caches the module in
sys.modules under its real name, 'tkinter'.
>>> import tkinter as tk
>>> import sys
>>> 'tkinter' in sys.modules
True
>>> 'tk' in sys.modules
False
'import tk.ttk' looks for 'tk' in sys.modules, does not find it, looks
for a module named 'tk' on disk, does not find it, and says so.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list