如何,以查看是否在Tkinter的存在插件? [英] How to see if a widget exists in Tkinter?

查看:1205
本文介绍了如何,以查看是否在Tkinter的存在插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我知道,你可以检查是否存在由一个窗口:

Now, I know that you can check to see if a window exists by:

x.winfo_exists()

返回一个布尔值。现在,我已经搜查,但一直没能找到正是我需要的。更具体地讲,我需要检查我的按钮,标签,列表框​​,滚动条的存在等等。

Which returns a Boolean. Now I have searched but haven't been able to find exactly what I need. More specifically I need to check the existence of my buttons, labels, list boxes, sliders etc.

推荐答案

winfo_exists ,除非你已经摧毁了小部件,在这种情况下,它返回0。此方法可以返回1任何Widget类,不仅Tk的根或Toplevels被调用。或者,你可以得到一个小部件的所有孩子与 winfo_children

winfo_exists returns 1 unless you have destroyed the widget, in which case it returns 0. This method can be called on any widget class, not only the Tk root or Toplevels. Alternatively, you can get all the children of a widget with winfo_children:

>>> import Tkinter as tk
>>> root = tk.Tk()
>>> label = tk.Label(root, text="Hello, world")
>>> label.winfo_exists()
1
>>> root.winfo_children()
[<Tkinter.Label instance at 0x0000000002ADC1C8>]
>>> label.destroy()
>>> label.winfo_exists()
0
>>> root.winfo_children()
[]

这篇关于如何,以查看是否在Tkinter的存在插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆