Muskovitz has asked for the wisdom of the Perl Monks concerning the following question:

i can't figure out why i can't create a new Gtk2 window here's the sample code

#!/usr/bin/perl use Gtk2 '-init'; use Glib qw/TRUE FALSE/; my $window=Gtk2::Window->new; $window->signal_connect('delete_event',sub{Gtk2->main_quit;}); my $vbox1=Gtk2::VBox->new; my $button=Gtk2::Button->new("Open a new Window"); $button->signal_connect(clicked=>sub{ &newWindow; }); $vbox1->add($button); $window->add($vbox1); $window->show_all; Gtk2->main; sub newWindow{ my $mw=Gtk2::Window->new('toplevel'); $mw->set_default_size(250, 250); Gtk2->main; }
very weird code, but the question is can i create a new gtk2 window w/ a button?

Replies are listed 'Best First'.
Re: I can't create a new Gtk2 window
by dave-theunsub (Scribe) on Jan 06, 2015 at 12:58 UTC
    Try removing the Gtk2->main in the newWindow subroutine, and replace it with $mw->show;. You already have the Gtk2->main in main:: and you don't need it again.

      how can i make this question `mark as solve`, you just solved my problem dude! ty

        Update your original post's title with '(SOLVED)' at the end.

        --MidLifeXis