判断实例是否已被销毁

发布于 2024-10-19 20:27:27 字数 60 浏览 6 评论 0原文

我有一个对象实例列表(wxPython 小部件)。我希望能够判断列表中的实例是否已被销毁。人们会怎样做呢?

I have a list of instances of objects (wxPython widgets). I'd like to be able to tell if an instance within my list has been destroyed. How would one go about this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄离 2024-10-26 20:27:27

wxPython 小部件在被销毁时为False。所以你可以简单地这样做:

if self.textCtrl:
   self.textCtrl...
else:
   return # textCtrl is destroyed

wxPython widgets are False when they're destroyed. So you can simply do this:

if self.textCtrl:
   self.textCtrl...
else:
   return # textCtrl is destroyed
Hello爱情风 2024-10-26 20:27:27

假设 wxPython 遵守规则,“销毁”意味着“不再被引用”,那么标准库中的 weakref 模块应该可以让你做你想做的事情(具体来说,你可以注册一个创建弱引用时的回调,在弱引用的目标被销毁之前调用)。

如果 wxPython 不遵守规则,或者禁用了对其对象的弱引用,那么您可能会不走运。

Assuming wxPython is playing by the rules and by "destroyed" you mean "is no longer referenced", then the weakref module in the standard library should let you do what you want (specifically, you can register a callback when creating a weak reference that is invoked just before the target of the weak reference is destroyed).

If wxPython isn't playing by the rules, or has disabled weak referencing for its objects, you may be out of luck.

瞳孔里扚悲伤 2024-10-26 20:27:27

这适用于所有wx.Window派生对象。如果它已被销毁或处置,则不会是 None,而是 False

This is applicable to all wx.Window derived objects. If it has been destroyed or disposed, it won't be None, but it will be False.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文