您的位置:首页 > 其它

怎么解决name 'Tkinter' is not defined 问题

2010-11-26 09:07 344 查看
默认情况下这个Tkinter都是安装好的,可是就是运行出错,说name 'Tkinter' is not defined 郁闷

发现python的每个版本都在更新,有时语句都在变化

这个问题百度基本没找到,在google找到了答案(关键词搜索“error Tkinter is not defined”)

http://www.python-forum.org/pythonforum/viewtopic.php?f=4&t=16856

这上面的回答并不鼓励使用from Tkinter import * 说是失去命名空间同时导致名字冲突

引用上面的一段话:

The example below gives you a nice short namespace, used by a lot of programmers, particularly sine Python3 has gone to a Tkinter package name tkinter.
import os, getpass, time #意思就是在python3以前用
With Python3 you simple change one line
import os, getpass, time #python3使用
import tkinter as tk

root = tk.Tk()

import Tkinter as tk

root = tk.Tk()

按照上面的说的成功解决问题,第一个gui出来了

#from tkinter import *  #第一步
#第二步,创建一个顶层窗口对象,来容纳整个GUI程序
#在您的顶层窗口的对象上创建所有的GUI模块
#把这些GUI模块与底层程序代码想连接
import os, getpass, time
import tkinter as tk

root = tk.Tk()
#top=Tkinter.Tk()#创建一个顶层窗口对象

label=tk.Label(root,text='hell world')
label.pack()
tk.mainloop()#进入主事件循环


呵呵,这个解决了,后面的都快了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐