Adding an icon to a ToolButton in Gtk 3

有些话、适合烂在心里 提交于 2019-12-10 10:59:54

问题


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

Below is my code:

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)

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

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


回答1:


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)


来源:https://stackoverflow.com/questions/10349642/adding-an-icon-to-a-toolbutton-in-gtk-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!