在Gtk 3中将图标添加到工具按钮 [英] Adding an icon to a ToolButton in Gtk 3

查看:153
本文介绍了在Gtk 3中将图标添加到工具按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将图标添加到Gtk.ToolButton(使用PyGi for Python的Gtk3)添加到GTK + 3工具栏?

Is there a way to add an icon to a Gtk.ToolButton (Gtk3 using PyGi for Python) to add to the GTK+3 toolbar ?

下面是我的代码:

self.addfile = Gtk.ToolButton()
self.addfile.set_label("Add File")
self.addfileimg = Gtk.Image()
self.addfileimg.show()
self.addfileimg.set_from_file(self.get_resource("img/file.png"))
self.addfile.set_icon_widget(self.addfileimg)
self.addfile.connect("clicked", self.on_open_file)

注意:get_resource()方法深入资源路径的本地工作文件夹,并且假定此方法在此上下文中有效.

Note: The get_resource() method digs into the local working folder for the resource path and this method is assumed working in this context.

我尝试使用PyGi编写上面的代码.图片文件有效,并且一切正常,但图片未显示.

I tried the code written above using PyGi. The image file is valid and everything is working but the image doesn't appear.

推荐答案

有一种名为set_icon_widget的GtkToolButton类的方法,该方法将GtkWidget实例作为其操作数. GtkImage是保存图像的容器.因此:

There is a method of the GtkToolButton class named set_icon_widget, taking a GtkWidget instance as its operand. GtkImage is a container that holds an image. Thus:

myToolButton.set_icon_widget(myImageWidget)

这篇关于在Gtk 3中将图标添加到工具按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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