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 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的更多相关文章
- 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.
随机推荐
- BitDefender(比特梵德)特惠活动 免费获取9个月激活码
Bitdefender为了庆祝自己获得2014年最佳杀毒软件,送出9个月的Internet security免费激活码.
- sprintf 函数
//$tick 保留{$decimalplaces}位小数,不够位数的小数点后面用0 填充$tick = sprintf( "%.0${decimalplaces}lf ", $i ...
- Linux 内核链表实现和使用(一阴一阳,太极生两仪~)
0. 概述 学习使用一下 linux 内核链表,在实际开发中我们可以高效的使用该链表帮我们做点事, 链表是Linux 内核中常用的最普通的内建数据结构,链表是一种存放和操作可变数据元 素(常称为节点) ...
- 【转】react的高阶组件
React进阶之高阶组件 前言 本文代码浅显易懂,思想深入实用.此属于react进阶用法,如果你还不了解react,建议从文档开始看起. 我们都知道高阶函数是什么, 高阶组件其实是差不多的用法,只 ...
- SWIFT中正则表达式验证邮箱
在playground内写入以下代码,正则关键字跟其它语言的没什么区别 class Regex { let internalExpression:NSRegularExpression let pat ...
- java的大数运算模板
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(S ...
- Vue.js中用webpack合并打包多个组件并实现按需加载
对于现在前端插件的频繁更新,所以多多少少要对组件化有点了解,下面这篇文章主要给大家介绍了在Vue.js中用webpack合并打包多个组件并实现按需加载的相关资料,需要的朋友可以参考下. 前言 随着 ...
- Vec3b类型数据确定颜色通道
前言 这几天实习生测试一张图像的三个通道分别是什么颜色,使用的是Vec3b类型,然后发现了一个有意思的点.. 测试过程 先创建了一定大小的数据, Mat test( , , CV_8UC3, Scal ...
- [LeetCode&Python] Problem 700. Search in a Binary Search Tree
Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST ...
- 网络编程初探--使用UDP协议的简易聊天室
UDP是一种无连接的传输层协议,提供快速不可靠的服务. 一.发送端 * 创建UDP发送端 * 步骤: * 1.建立UDP的Socket服务 * 2.将要发送的数据封装到数据包中 * 3.通过UDP的s ...