首页 > 其他 > 详细

Tkinter中Widget名称

时间:2017-06-03 12:07:21      阅读:321      评论:0      收藏:0      [点我收藏+]
 If you wish to get the full name of a Tkinter widget, simply use the str function on the widget instance:

Tkinter中欲获取Widget名称,只要使用print打印对应Widget实例即可

而在Widget创建时,可以通过设置name属性,指定名称,而name属性只能在对象创建时使用

 

未设置name属性

from Tkinter import *

root = Tk()
frame = Frame(root)
print frame
ok = Button(frame,text="ok")
print ok

输出:

.35331768
.35331768.35344632

 

 设置name属性

root = Tk()
frame = Frame(root, name="dialog")
print frame
ok = Button(frame, name="ok")
print ok
ok.name = "cancel"  # name属性只在对象创建时有效,对象一经创建,name属性就不能被修改
print str(ok)

输出:

.dialog
.dialog.ok
.dialog.ok

 

Tkinter中Widget名称

原文:http://www.cnblogs.com/hupeng1234/p/6936718.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!