Re: Why can't I create buttons in a for loop?
- From: dov imagic weizmann ac il
- To: christopher bergeron com
- Cc: gtk-perl-list gnome org
- Subject: Re: Why can't I create buttons in a for loop?
- Date: Sun, 4 Nov 2001 07:26:06 IST
The problem is that you can only add one single child to the main
window. If you want more than one child, you have to place them
in a packer widget. E.g. a vbox. Here is your program where this
has been fixed.
Regards,
Dov
#!/usr/bin/perl -w
use Gtk; # load the Gtk-Perl module
use strict; # a good idea for all non-trivial Perl scripts
set_locale Gtk; # internationalize
init Gtk; # initialize Gtk-Perl
my $window = new Gtk::Window( "toplevel" );
my $bw=5;
# callback registration
$window->signal_connect("delete_event", \&CloseAppWindow);
$window->border_width( $bw );
my @pornstar=("a","b","c","d","e","f","g","h","i","j");
my $i=0;
my @button=("1","2","3","4","5");
my $vbox = new Gtk::VBox();
$window->add($vbox);
$vbox->show();
for ($i=0;$i<5;$i++) {
$button[$i] = new Gtk::Button("$pornstar[$i]");
$button[$i]->signal_connect("clicked", \&CloseAppWindow);
$button[$i]->show();
$vbox->pack_start_defaults($button[$i]);
}
$window->show();
main Gtk;
sub CloseAppWindow
{
Gtk->exit(0);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]