Python GTK +小部件名称 [英] Python GTK+ widget name

查看:138
本文介绍了Python GTK +小部件名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我使用Glade定义一个GUI时,我可以命名窗口的窗口小部件,但我怎么才能获得窗口小部件的名称?当我有一个小部件对象实例时恢复该属性?



我试过 get_property() get_name() $ widget.name 无效。

更新:我使用的是GtkBuilder文件格式(即XML格式)。

解决方案: :在从> GtkBuilder 中获取它之后,使用小部件上的 set_property(name,name) p>

解决方案

我使用class-method表单,它适用于我:

 gtk.Buildable.get_name(小工具)






参考文献



PyGtk: gtk.Buildable.g et_name



Gtk3: Gtk.Buildable.get_name



来自 gtk2 GtkBuilder


在GTK + 2.20之前, gtk.Builder将
构造的小部件的name属性设置为id属性。在GTK + 2.20或更新版本中,您
必须使用gtk.Buildable.get_name()而不是gtk.Widget.get_name()
来获取id,或者在您的name属性中设置UI定义。







进一步



有一些报告的错误,其中GtkBuilder将小部件名称设置为构建器ID,或者根本没有设置它。请参阅 Ubuntu GNOME bug。我不知道为什么这些bug说它设置了ID而不是名字,因为我只见过没有设置的名字。


How do I get a widget's "name"?

When I define a GUI using Glade, I can "name" the widgets of the window but how do I recover that property when I have a widget object instance?

I've tried get_property(), get_name() and $widget.name to no avail.

Update: I am using GtkBuilder file format (i.e. XML format).

Resolution: a fix I have used: use the set_property("name", name) method on the widget just after getting it from GtkBuilder.

解决方案

I use the class-method form, which works for me:

gtk.Buildable.get_name(widget)


References

PyGtk: gtk.Buildable.get_name

Gtk3: Gtk.Buildable.get_name

Quote from gtk2 GtkBuilder:

Prior to GTK+ 2.20, gtk.Builder was setting the "name" property of constructed widgets to the "id" attribute. In GTK+ 2.20 or newer, you have to use gtk.Buildable.get_name() instead of gtk.Widget.get_name() to obtain the "id", or set the "name" property in your UI definition.


Further

There were some reported bugs where GtkBuilder sets the widget name to be the builder ID, or doesn't set it at all. See Ubuntu and GNOME bugs. I have no idea why the bugs says that it sets the ID instead of the name as I've only ever seen the name not set.

这篇关于Python GTK +小部件名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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