原文https://stackoverflow.com/questions/15974787/difference-between-import-tkinter-as-tk-and-from-tkinter-import

from Tkinter import * imports every exposed object in Tkinter into your current namespace.

import Tkinter imports the "namespace" Tkinter in your namespace and import Tkinter as tkdoes the same, but "renames" it locally to 'tk' to save you typing

let's say we have a module foo, containing the classes A, B, and C.

Then import foo gives you access to foo.A, foo.B, and foo.C.

When you do import foo as x you have access to those too, but under the names x.A, x.B, and x.C. from foo import * will import A, B, and C directly in your current namespace, so you can access them with A, B, and C.

There is also from foo import A, C wich will import A and C, but not B into your current namespace.

You can also do from foo import B as Bar, which will make B available under the name Bar (in your current namespace).

So generally: when you want only one object of a module, you do from module import object or from module import object as whatiwantittocall.

When you want some modules functionality, you do import module, or import module as shortname to save you typing.

from module import * is discouraged, as you may accidentally shadow ("override") names, and may lose track which objects belong to wich module.

python3 from Tkinter import * 和import Tkinter as tk两个区别import Tkinter的更多相关文章

  1. Tk 的基本概念-组件—Tkinter 教程系列03

    Tk 的基本概念-组件-Tkinter 教程系列03 前言 Tk 系列教程: Tkinter教程系列01--引言和安装Tk Tkinter教程系列02--第一个真正的 GUI 程序 通过上一节的程序实 ...

  2. python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别

    python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别 os.path.realpath 获取当前执行脚本的绝对路径. os.path.rea ...

  3. python3.4学习笔记(四) 3.x和2.x的区别,持续更新

    python3.4学习笔记(四) 3.x和2.x的区别 在2.x中:print html,3.x中必须改成:print(html) import urllib2ImportError: No modu ...

  4. python3爬虫应用--爬取网易云音乐(两种办法)

    一.需求 好久没有碰爬虫了,竟不知道从何入手.偶然看到一篇知乎的评论(https://www.zhihu.com/question/20799742/answer/99491808),一时兴起就也照葫 ...

  5. Python3.x:os._exit(), sys.exit(), exit() 的区别

    Python3.x:os._exit(), sys.exit(), exit() 的区别 一.sys.exit() 说明:退出程序引发SystemExit异常, 可以捕获异常执行些清理工作.一般主程序 ...

  6. Python3.5以上Celery4.2.1启动报错:ImportError: cannot import name 'LRUCache' from 'kombu.utils.functional'

    服务器:Centos7 Python版本:Python 3.7.0 Celery版本:4.2.1 Python3.5以上,OrderDict不允许在迭代过程中进行修改,导致LRUCache.updat ...

  7. error: not found: value sqlContext/import sqlContext.implicits._/error: not found: value sqlContext /import sqlContext.sql/Caused by: java.net.ConnectException: Connection refused

    1.今天启动启动spark的spark-shell命令的时候报下面的错误,百度了很多,也没解决问题,最后想着是不是没有启动hadoop集群的问题 ,可是之前启动spark-shell命令是不用启动ha ...

  8. 【微信小程序】在js中导入第三方js或自己写的js,使用外部js中的function的两种方法 import和require的区别使用方法 【外加:使用第三方js导出的默认function的调用方法】

    如下 定义了一个外部js文件,其中有一个function import lunaCommon from '../lunaCommon.js'; var ctx = wx.getStorageSync( ...

  9. import: not authorized `time' @ error/constitute.c/WriteImage/1028. import: not authorized `rospy' @ error/constitute.c/WriteImage/1028.

随机推荐

  1. win10下用u盘装centos后如何修复win10引导

    相关参考: http://www.cnblogs.com/xiaoyao-lxy/p/5561728.html#wu

  2. [追加评论]三款SDR平台对比:HackRF,bladeRF和USRP

    这三个月,有幸把3种板子都用到了.说说使用体会.   我用过其中的HackRF,bladeRF x115,USRP B210.我并没有仔细的测量各种板子的射频指标什么的,只是做各种实验的时候用到它们. ...

  3. Android2.1消息应用(Messaging)

    我想首先应该从AndroidManifest.xml文件开始,该文件是Android应用(APK)的打包清单,其中提供了关于这个应用程序的基本信息,如名称(application/@label),图标 ...

  4. SWIFT 之CoreData初试

    SWIFT中使用CoreData来保存本地数据,在建立项目的时候把 "Use Core Data"选项选上 项目建立完成后点击后缀为 .xcdatamodeld的那个文件,点击右下 ...

  5. WinRAR的自解压模式 - imsoft.cnblogs

    一个 SFX (SelF-eXtracting)自解压文件是压缩文件的一种,它结合了可执行文件模块,一种用以运行从压缩文件解压文件的模块.这样的压缩文件不需要外部程序来解压自解压文件的内容,它自己便可 ...

  6. poj-1112 (二分图染色+dp分组)

    #include <iostream> #include <algorithm> #include <cstring> using namespace std; ; ...

  7. Xcode7( linker command failed with exit code 1)

    ”Build Settings”->”Enable Bitcode”设置为NO ,因为有些SDK不支持Bitcode

  8. javascript : location 对象

    window.location: window的location对象 window.location.href 整个URl字符串(在浏览器中就是完整的地址栏) window.location.prot ...

  9. 【BZOJ1702】[usaco2007margold]队列平衡

    原来蛤习线性探测的时候要每次加一个稍大一点的数而不是每次+1……连蛤习都不会写,我tmd是有多弱 原题: N(1<=N<=100000)头牛,一共K(1<=K<=30)种特色, ...

  10. day43 数据库学习egon的博客 约束

    一 介绍 约束条件与数据类型的宽度一样,都是可选参数 作用:用于保证数据的完整性和一致性主要分为: PRIMARY KEY (PK) 标识该字段为该表的主键,可以唯一的标识记录 FOREIGN KEY ...