Reputation: 101
I am trying to make a simple image viewer where you put the filename of an image including its extension but the image doesn't pack in the Main window
#!/usr/bin/perl
use strict;
use warnings;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
my $window=Gtk2::Window->new();
$window->set_title("Image Resizer");
$window->signal_connect('delete_event',sub{Gtk2::main_quit;});
my $vbox1=Gtk2::VBox->new;
my $label=Gtk2::Label->new("Image Filename: ");
my $entry=Gtk2::Entry->new;
my $button=Gtk2::Button->new("Submit");
$button->signal_connect(clicked=>sub{
my $string=$entry->get_text;
my $label1=Gtk2::Label->new("$string");
$vbox1->add($label1);
my $pbuf=Gtk2::Gdk::Pixbuf->new_from_file_at_size("$string", 200, 200);
my $image=Gtk2::Image->new_from_pixbuf($pbuf);
$vbox1->add($image);
});
$vbox1->add($label);
$vbox1->add($entry);
$vbox1->add($button);
$window->add($vbox1);
$window->show_all;
Gtk2->main;
I am making this example as a part of a perl/gtk2 tutorial but can't figure out the source of the bug.
Upvotes: 2
Views: 216
Reputation: 11588
It does pack; you need to explicitly call show_all
on any widgets you add after the window has already been shown (in this case, to $label1
and $image
).
Upvotes: 2