我如何从GTK Builder中检索对象的名称? [英] How can I retrieve from a GTK Builder the name of an object?

查看:116
本文介绍了我如何从GTK Builder中检索对象的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获取从Builder对象中检索的Gtk.Widget的名称?



具体指的是在Glade中看到的名称(例如: button1 ),而不是类的名称( GtkWindow )。



这个问题与这一个完全一样,但对于使用GObject内省的Python。

解决方案

您不能使用从继承的 get_name 方法> Gtk .Widget 。相反,您必须使用 Gtk.Buildable 中定义的 get_name 方法,如下所示:

button = builder.get_object(button1)
print(Gtk.Buildable.get_name(button)) #打印button1


How do I get the name of a Gtk.Widget retrieved from a Builder object?

I specifically mean the name seen in Glade (eg: button1), not the name of the class (GtkWindow).

This question is exactly the same as this one, but for Python with GObject introspection.

解决方案

You can't use the get_name method inherited from Gtk.Widget. Instead, you have to use the get_name method defined in Gtk.Buildable, like this:

button = builder.get_object("button1")
print(Gtk.Buildable.get_name(button)) # prints "button1"

这篇关于我如何从GTK Builder中检索对象的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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