Difference between import tkinter as tk and from tkinter import

前端 未结 3 518
陌清茗
陌清茗 2020-12-01 08:24

I know it is a stupid question but I am just starting to learn python and i don\'t have good knowledge of python. My question is what is the difference between



        
3条回答
  •  粉色の甜心
    2020-12-01 09:02

    You can certainly use

    import Tkinter
    

    However, if you do that, you'd have to prefix every single Tk class name you use with Tkinter..

    This is rather inconvenient.

    On the other hand, the following:

    import Tkinter as tk
    

    sidesteps the problem by only requiring you to type tk. instead of Tkinter..

    As to:

    from Tkinter import *
    

    it is generally a bad idea, for reasons discussed in Should wildcard import be avoided?

提交回复
热议问题