I can’t seem to find a way to create menubar and a simple button.
With my current code, it will spawn two windows at the same time – one is just one big button and the other one is a file menu.
let window = gtk::ApplicationWindow::new(app);
window.set_title("First GTK Program");
let button = gtk::Button::with_label("Click me!");
// initialize the button
let menubar = {
let file_menu = {
let about_menu_item = gio::MenuItem::new(Some("About"), Some("app.about"));
let quit_menu_item = gio::MenuItem::new(Some("Quit"), Some("app.quit"));
let file_menu = gio::Menu::new();
file_menu.append_item(&about_menu_item);
file_menu.append_item(&quit_menu_item);
file_menu
};
let menubar = gio::Menu::new();
menubar.append_submenu(Some("File"), &file_menu);
menubar
};
app.set_menubar(Some(&menubar));
app.set_child(Some(&button));
I think it is somewhere here that I do not set it up correctly. Should I use app.set_child
? Or do I have to use hbox
?
New contributor
Evil Dragon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.