The missing piece of this jigsaw puzzle is realising that Gio.MenuItems themselves have attribute-values.
So in this case, before adding the menu-item to the GMenu the syntax required is:
item.set_attribute_value("accel", GLib.Variant("s", "<Alt>Z"))
To complete the answer, you can also set the label and action for the menu-item in this way:
item = Gio.MenuItem() item.set_attribute_value("label", GLib.Variant("s", "RandomAlbum")) item.set_attribute_value("action", GLib.Variant("s", "app."+action_name))
However the methods set_label
and set_detailed_action
perform the same role.