Am 14.06.18 um 05:14 schrieb huey.y.ji...@gmail.com:
root = Tkinter.Tk()
button = Tkinter.Button(root, text="Find me")
button.pack()

I created a button, Python object. I recall I can check this object existing by using winfo, such as winfo.exists(button). However, I forgot which super class contains this winfo method. I printed out dir(os), dir(sys), dir(Tkinter), but did not find this winfo method. I wonder who will be kindly drop down a few lines?
This is due to a bad wrapping of the original Tcl interface of Tk. In the original Tcl, "winfo" is not a method of anything, it is a free function. In TkInter, all free functions that accept a widget as the first parameter were made methods of that widget. Therefore, "winfo_exists" is a method of "button", which is logically contorted: you are asking an object "do you exist?".

However, since it can be explicitly destroyed, this can still be useful:

>>> import Tkinter
>>> root = Tkinter.Tk()
>>> button = Tkinter.Button(root, text="Find me")
>>> button.pack()
>>> button.winfo_exists()
1
>>> button.destroy()
>>> button.winfo_exists()
0

I am not sure that this is very helpful, though. Usually you don't destroy a button yourself, it is done by the destructor when the button is deleted, and therefore, winfo_exists() under normal circumstances returns true. What are you really trying to achieve?

        Christian
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to