I'm assembling a GUI using PyGObject. This Python code works in context. I get a toolbar button with the stock "Open" icon.
from gi.repository import Gtk
# ...
toolbar = Gtk.Toolbar()
toolbar.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)
# ...
self.fileOpen = Gtk.ToolButton.new_from_stock(Gtk.STOCK_OPEN)
self.fileOpen.connect("clicked", self.on_FileOpenStandard_activate)
toolbar.insert(self.fileOpen, -1)
But according to this resource, new_from_stock()
is deprecated:
Deprecated since version 3.10: Use
Gtk.ToolButton.new ()
together withGtk.Image.new_from_icon_name ()
instead.
Okay then. So after digging further, this is what I came up with for a replacement:
self.fileOpen = Gtk.ToolButton(
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)
But this is the result:
What is the correct way to do this that is still supported by the current GTK library?
new()
methods.This should work equally well:Gtk.ToolButton(icon_widget=openIcon, label="Open")
– Barman