python3 from Tkinter import * 和import Tkinter as tk两个区别import Tkinter
原文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 tk
does 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的更多相关文章
- Tk 的基本概念-组件—Tkinter 教程系列03
Tk 的基本概念-组件-Tkinter 教程系列03 前言 Tk 系列教程: Tkinter教程系列01--引言和安装Tk Tkinter教程系列02--第一个真正的 GUI 程序 通过上一节的程序实 ...
- python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别
python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别 os.path.realpath 获取当前执行脚本的绝对路径. os.path.rea ...
- python3.4学习笔记(四) 3.x和2.x的区别,持续更新
python3.4学习笔记(四) 3.x和2.x的区别 在2.x中:print html,3.x中必须改成:print(html) import urllib2ImportError: No modu ...
- python3爬虫应用--爬取网易云音乐(两种办法)
一.需求 好久没有碰爬虫了,竟不知道从何入手.偶然看到一篇知乎的评论(https://www.zhihu.com/question/20799742/answer/99491808),一时兴起就也照葫 ...
- Python3.x:os._exit(), sys.exit(), exit() 的区别
Python3.x:os._exit(), sys.exit(), exit() 的区别 一.sys.exit() 说明:退出程序引发SystemExit异常, 可以捕获异常执行些清理工作.一般主程序 ...
- 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 ...
- 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 ...
- 【微信小程序】在js中导入第三方js或自己写的js,使用外部js中的function的两种方法 import和require的区别使用方法 【外加:使用第三方js导出的默认function的调用方法】
如下 定义了一个外部js文件,其中有一个function import lunaCommon from '../lunaCommon.js'; var ctx = wx.getStorageSync( ...
- import: not authorized `time' @ error/constitute.c/WriteImage/1028. import: not authorized `rospy' @ error/constitute.c/WriteImage/1028.
随机推荐
- Java通过继承外部类来建立该外部类的protected内部类的实例(转)
原文链接:http://blog.sina.com.cn/s/blog_7de00ff60102xffx.html 如果想要在外部类的导出类(子类)中建立该外部类的为protected权限的内部类的实 ...
- 关于send message 函数
Windows是一个消息驱动模式的系统,SendMessage 是应用程序和应用程序之间进行消息传递的主要手段之一.由于 SendMessage 函数的参数选项过于繁多,因此很有必要作一个汇总,分门别 ...
- Redis Cluster(Redis集群)的搭建和使用
Reids集群准备知识: (1)Redis集群介绍 Redis 集群是一个提供在多个Redis间节点间共享数据的程序集. Redis集群并不支持处理多个keys的命令,因为这需要在不同的节点间移动数据 ...
- iframe 问题集合
1. 历史记录问题 Firefox: 如果iframe是静态存在在HTML中时,iframe的任何src或者location改变都会被记录到浏览器history中. 如果iframe是在页面加载完成后 ...
- vue|html5 form 验证
html:<form id="scoreForm" @submit="fsub" > <template v-for="(item, ...
- HDU 3376
http://acm.hdu.edu.cn/showproblem.php?pid=3376 题意:一个矩阵,每个点有价值,起点左上角终点右下角,每次只能走当前点的下一点或右一点,从起点走到终点,再从 ...
- 一个两年Java的面试总结
前言 16年毕业到现在也近两年了,最近面试了阿里集团(菜鸟网络,蚂蚁金服),网易,滴滴,点我达,最终收到点我达,网易offer,蚂蚁金服二面挂掉,菜鸟网络一个月了还在流程中...最终有幸去了网易.但是 ...
- Springboot中使用缓存
在开发中,如果相同的查询条件去频繁查询数据库, 是不是会给数据库带来很大的压力呢?因此,我们需要对查询出来的数据进行缓存,这样客户端只需要从数据库查询一次数据,然后会放入缓存中,以后再次查询时可以从缓 ...
- 模板引擎之jade 学习
jade 模板引擎在node express 开发中有较多的使用,首先我们看一个简单的使用jade 生成的html 页面的标签代码: doctype html html(lang="en&q ...
- zeroMQ 学习
zeroMQ 是一个高性能的分布式设计的消息队列,网上有人进行过性能的比较,非常厉害,并且很大约40多种语言的API 可以调用,真实很不错的. 而且有一点就是使用简单,不需要服务器,对于使用C/C++ ...