title: How to create PyGObject application with a menubar using Gtk.Builder?
body: <p>There is no full documentation about how to use <code>Gtk.Builder</code> in <code>PyGObject</code> to create a menubar.</p>
  
  <p>I don't use that <code>Gtk.UIManager</code> because it is deprecated.
  The example code below is based on my experience with <code>Gtk.UIManager</code>.</p>
  
  <p>In the example should appear a menubar with <em>Foo</em> as a top menu group having an clickable item <em>Bar</em>.</p>
  
  <pre><code>#!/usr/bin/env python3
  import gi
  gi.require_version('Gtk', '3.0')
  from gi.repository import Gtk
  from gi.repository import Gio
  
  class Window(Gtk.ApplicationWindow):
      def __init__(self):
          Gtk.Window.__init__(self)
          self.set_default_size(200, 100)
  
          #
          self.interface_info = """
          &lt;interface&gt;
            &lt;menu id='TheMenu'&gt;
              &lt;section&gt;
                &lt;attribute name='foo'&gt;Foo&lt;/attribute&gt;
                &lt;item&gt;
                  &lt;attribute name='bar'&gt;Bar&lt;/attribute&gt;
                &lt;/item&gt;
              &lt;/section&gt;
            &lt;/menu&gt;
          &lt;/interface&gt;
          """
  
          builder = Gtk.Builder.new_from_string(self.interface_info, -1)
  
          action_bar = Gio.SimpleAction.new('bar', None)
          action_bar.connect('activate', self.on_menu)
          self.add_action(action_bar)
  
          menubar = builder.get_object('TheMenu')
  
          # layout
          self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
          self.layout.pack_start(menubar, True, True, 0)
          self.add(self.layout)
  
          self.connect('destroy', Gtk.main_quit)
          self.show_all()
  
      def on_menu(self, widget):
          print(widget)
  
  if __name__ == '__main__':
      win = Window()
      Gtk.main()
  </code></pre>
  
  <p>The current error is</p>
  
  <pre><code>Traceback (most recent call last):
    File "./_menubar.py", line 46, in &lt;module&gt;
      win = Window()
    File "./_menubar.py", line 36, in __init__
      self.layout.pack_start(menubar, True, True, 0)
  TypeError: argument child: Expected Gtk.Widget, but got gi.repository.Gio.Menu
  </code></pre>
  
  <p>I am unsure about</p>
  
  <ul>
  <li>How to create the XML string.</li>
  <li>How to get the menubar-widget.</li>
  <li>How to create Actions/Click-handlers for menu items.</li>
  </ul>
  
  <p>Of course the question could be extended to toolbars but I wouldn't made it to complexe.</p>
  
  <p>btw: I don't want to use <code>Gtk.Application.set_menubar()</code>. Because there is no <code>Gtk.Application.set_toolbar()</code> and currently I see no advantage on having a Gtk-based application object.</p>
  
  <p><strong>EDIT</strong>: I also tried this variant (without any success):</p>
  
  <pre><code>gio_menu = builder.get_object('TheMenu')
  menubar = Gtk.Menubar.new_from_model(gio_menu)
  </code></pre>