python-2.7 - gtk : find if a widget is from some type

标签 python-2.7 pygtk equality

我正在尝试查找 gtk 中的某些小部件是否是 ComboBox 小部件。 这个词在这里似乎不起作用

def set_entries_editable(self, bool, widget):
    '''define whether to enable/disable widget'''
        if widget is gtk.ComboBoxEntry:
            widget.set_sensitive(bool)
        else:
            widget.set_editable(bool)

谢谢!

最佳答案

is用于检查对象身份。

>>> a = [1, 2]
>>> b = [1, 2]
>>> a is b
False
>>> a is a
True

使用isinstance检查对象是否是特定类型的实例:

>>> isinstance(a, list)
True

if isinstance(widget, gtk.ComboBoxEntry):

关于python-2.7 - gtk : find if a widget is from some type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24389692/

相关文章:

python - 为什么我会收到这个 NameError?我没有正确使用它吗?

c++ - 为什么 ("Maya"== "Maya") 在 C++ 中不是真的?

python - 如何处理多个通用用户界面?

java - 如何在 Java 中比较字符串?

php - php 中 == 和 === WRT 数组的区别?

python - 同时运行多个相互通信的 Kivy 应用程序

python - 将 Python 生成器解压为参数——内存效率高吗?

Python:子类化 frozenset 不可迭代?

python - PyGTK 应用程序的主类是否应该扩展 Gtk.Window?

Python open() 模式和文件写入