How to see if a widget exists in Tkinter?

前端 未结 2 1752
伪装坚强ぢ
伪装坚强ぢ 2021-01-02 07:51

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

x.winfo_exists()

Which returns a Boolean. I have searched for this, but haven\

2条回答
  •  半阙折子戏
    2021-01-02 08:21

    You can also print the type i.e.. type(label). This can be helpful to provide not only existence, but also find if anything is coming up 'NoneType' without an error. The type() will tell you if you have an instance, or other type that can provide valuable clues as to how close the program is performing or returning items to what you think you are asking! The object.winfo_exists() and object.winfo_children is specific, and will throw an error if the object is not a type 'instance'.

提交回复
热议问题