Looking at this C ++ GitHub example , I am surprised to find a direct call to the static function new() , not the constructor.
So I decided to give it a try. Look carefully at the difference. It is subtle.
#vvv self.fileOpen = Gtk.ToolButton.new( Gtk.Image.new_from_icon_name("document-open", Gtk.IconSize.LARGE_TOOLBAR), "Open") self.fileOpen.connect("clicked", self.on_FileOpenStandard_activate) toolbar.insert(self.fileOpen, -1)
To my surprise, this displays an icon where there is no other approach.
Bonus: Clean version above:
# iconSize to be reused iconSize = Gtk.IconSize.LARGE_TOOLBAR # ... openIcon = Gtk.Image.new_from_icon_name("document-open", iconSize) self.fileOpen = Gtk.ToolButton.new(openIcon, "Open") self.fileOpen.connect("clicked", self.on_FileOpenStandard_activate) toolbar.insert(self.fileOpen, -1)
source share