Kan-Ru Chen's Weblog

Perl and Gtk2 menu

今天主要學到了選單(menu)的寫法,不過它使用的資料型態我看不太懂,似乎跟物件有關,看起來很奇怪。

以下是有關menu部份的code

    use Gtk2::SimpleMenu;
    my $menu_tree = [
        _File => {
        	item_type => "<Branch>",
        	children => [
        		_Quit => {
        			callback => sub { Gtk2->main_quit;},
        			callback_action => 0,
        			accelerator => "<ctrl>Q",
        			},
        		]
        	}
        ];
    my $menu = Gtk2::SimpleMenu->new (
        menu_tree => $menu_tree,
        default_callback => sub { print "hello";},
        user_data => "user_data"
        );
    $vbox->pack_start ($menu->{widget},0 ,0 ,0);