I'm using gotk3 (a project that provides Go bindings for GTK+3) for writing a simple GUI application. I'd like to show a menu bar in the application but now it doesn't show any menu (tested on both MacOSX and Linux). This is the code:
package main
import (
"github.com/gotk3/gotk3/gtk"
"log"
)
func main() {
gtk.Init(nil)
// creates window
win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
if err != nil {
log.Fatal("Unable to create window:", err)
}
win.SetDefaultSize(800, 600)
win.Connect("destroy", func() {
gtk.MainQuit()
})
// creates grid and label
grid, err := gtk.GridNew()
if err != nil {
log.Fatal("Unable to create grid:", err)
}
label, _ := gtk.LabelNew("Hello, gotk3!")
grid.Add(label)
// creates menu
menuBar, err := gtk.MenuBarNew()
if err != nil {
log.Fatal("Unable to create menubar:", err)
}
menu, err := gtk.MenuNew()
if err != nil {
log.Fatal("Unable to create menu:", err)
}
menu.SetName("File")
menuItem, err := gtk.MenuItemNewWithLabel("Open")
if err != nil {
log.Fatal("Unable to create menuitem:", err)
}
menu.Append(menuItem)
// attaches menubar to grid
grid.Attach(menuBar, 0, 0, 200, 200)
// shows window
win.Add(grid)
win.ShowAll()
gtk.Main()
}
Since it doesn't work I don't think that Attach()
is the right function for doing this. I never worked with GTK+, so almost no idea of what to do or where to look. Any hint?
Thanks, Andrea