Button 我怎样才能按下headerbar的按钮,在vala的窗口中做事

Button 我怎样才能按下headerbar的按钮,在vala的窗口中做事,button,window,gtk3,vala,Button,Window,Gtk3,Vala,如何在headerbar中制作按钮并在窗口中执行我尝试过的操作: public class headerbar : Gtk.HeaderBar { construct { title = "Quiz"; subtitle = "You can solve this!"; show_close_button = true; Gtk.Button button = new Gtk.Button.with_label ("Quit

如何在headerbar中制作按钮并在窗口中执行我尝试过的操作:

public class headerbar : Gtk.HeaderBar {
    construct {
        title = "Quiz";
        subtitle = "You can solve this!";
        show_close_button = true;
        Gtk.Button button = new Gtk.Button.with_label ("Quit");
        button.get_style_context ().add_class ("suggested-action");
        button.set_valign (Gtk.Align.CENTER);
        button.clicked.connect (() => {
            var label = new Gtk.Label ("Hi");
            main.add (label);
            label.show ();
        });
        pack_start (button);
    }
}

我得到的样本如下,希望能对您有所帮助:

公共类应用程序标题栏:Gtk.HeaderBar{ 私人Gtk.按钮m_new_tab_按钮; 私人Gtk.Box m_应用程序_标题_gui_Box; 专用Gtk.MenuButton m_主菜单按钮; 公共弱工作台工作台{get;construct;} 公共AppTitleBar工作台{ 对象工作台:工作台; } 构造{ 设置\显示\关闭\按钮为真; 这是一个.build\u title\u bar\u布局; } public void add_new_tabWidget title_widget { m_app_title_gui_box.pack_starttitle_小部件; title_widget.focus.connect=>{ 此.update\u选项卡\u inactive\u all; 返回true; }; } 公共无效更新\u选项卡\u非活动\u全部 { m_app_title_gui_box.foreach小部件=>{ widget.set_opacity 0.3; }; } 公共无效删除\u选项卡\u widgetWidget选项卡\u栏 { m_app_title_gui_box.removetab_bar; } 专用空心建筑\标题\栏\布局 { m_主菜单按钮=新建Gtk.menu按钮; var menu_image=新建Gtk.image.from_icon_name打开菜单符号,Gtk.IconSize.BUTTON; m_主菜单按钮。设置图像菜单图像; m_主菜单按钮。工具提示文本=主菜单; //创建标题栏框 m_app_title_gui_box=new BoxOrientation.HORIZONTAL,2; //创建添加新选项卡按钮 m_new_tab_button=新建Gtk.button.from_icon_namelist-add,Gtk.IconSize.button; m_new_tab_button.get_style_context.add_class back button; m_new_tab_button.valign=Gtk.Align.CENTER; m_新建选项卡按钮。始终显示图像=真; m_new_tab_button.can_focus=false; m_new_tab_button.action_name=WorkbenchActions.action_PREFIX+WorkbenchActions.action_tab_new; m_new_tab_button.has_tooltip=true; m_new_tab_button.tooltip_text=打开新连接Ctrl+N; 此.pack\u endm\u主菜单按钮; 此.pack\u startm\u app\u title\u gui\u框; 此.pack_startm_new_tab_按钮; } }