Why/how does named vs wildcard import affect parameters?

久未见 提交于 2019-12-06 10:49:56
from tkinter import *

Loads everything from tkinter module, and puts it in the global namespace.


import tkinter as tk

Loads everything from tkinter module, and put it all in the tk namespace. So Label is now tk.Label, and W is tk.W


Your third option, which is better when you only need a few objects from the module, would be:

from tkinter import Label, Entry, Button, W, E, Tk

Etc. Again, better when you just need one or two. Not good for your situation. Just included for completeness.


Fortunately you only have one import * or you'd have a much harder time determining which module everything came from!


Edit:

tkinter.W = 'w'
tkinter.E = 'e'
tkinter.S = 's'
tkinter.N = 'n'

They're just constants. You could pass the string value and it would work just as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!