I’ve been working with Perl for years and recently started learning how to do GUI via Gtk2. All examples and tutorials I’ve found illustrate simple one-window type applications. Anything with a second window is limited to a simple text entry or yes/no type dialogue. I want to learn how to build something with that next-step more complex. I know how to build the windows, etc. (manually, or via Glade) but I don’t understand how to tie the program flow together.
I’m willing to buy books, etc. but I’ve only seen ones for C (and not in-stock, I’d have to order them unseen) and I’m worried the differences to Perl::Gtk2 might still add too much complexity. Can anyone either provide me an example, or point me to a tutorial, etc.
Thanks much,
Adam
I’ve been doing Perl/GTK development for a couple years now and know what your talking about. Gtk2::Ex::FormFactory is a neat module but wasn’t really my thing and definitely not necessary for building a complex Perl/GTK app. All widgets, including windows, in Perl/GTK support the show/hide method. Plus you can have as many toplevel windows as you want and just show and hide them as needed. Here’s a simple example of switching between multiple windows:
#!/usr/bin/perl use Glib qw/TRUE FALSE/; use Gtk2 '-init'; $window = Gtk2::Window->new('toplevel'); $window->signal_connect(delete_event => sub { Gtk2->main_quit; }); $window->set_border_width(10); $window->set_title("Window 1"); $window->set_position('center'); $button = Gtk2::Button->new("Switch to Window 2"); $button->signal_connect(clicked => sub { $window->hide; $window2->show; }); $window->add($button); $button->show; $window2 = Gtk2::Window->new('toplevel'); $window2->signal_connect(delete_event => sub { Gtk2->main_quit; }); $window2->set_border_width(10); $window2->set_title("Window 2"); $window2->set_position('center'); $button2 = Gtk2::Button->new("Switch to Window 1"); $button2->signal_connect(clicked => sub { $window2->hide; $window->show; }); $window2->add($button2); $button2->show; $window->show; Gtk2->main;