Just for your advancement, Gtk2 has a nice multicolumn select-drop-down widget.
#! /usr/bin/perl use warnings; use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; use MIME::Base64; use Imager; my %bunnies; #global hash to hold build_bunnies(); #standard window creation, placement, and signal connecting my $window = Gtk2::Window->new('toplevel'); $window->signal_connect('delete_event' => sub { Gtk2->main_quit; }); $window->set_border_width(5); $window->set_position('center_always'); #this vbox will return the bulk of the gui my $vbox = &ret_vbox(); #add and show the vbox $window->add($vbox); $window->show(); #our main event-loop Gtk2->main(); ################################## sub ret_vbox { my $vbox = Gtk2::VBox->new(FALSE,5); my $list_store = Gtk2::ListStore->new ('Glib::String', 'Gtk2::Gdk::Pi +xbuf'); #fill it with arbitry data foreach (0..11) { my $iter = $list_store->append; # Usage: $liststore->set ($iter, column1, value1, column +2, value2, ...) #$list_store->set ($iter, 0 =>$pbufs[0] , 1 => "ZZZ x $_"); $list_store->set ($iter, 0 => "ZZZ x $_"); $list_store->set ($iter, 1 => $bunnies{$_} ); } # my $combo_box = Gtk2::ComboBox->new_text; #will cause slew of +errors with pixbufs # $combo_box->set_model($list_store); my $combo_box = Gtk2::ComboBox->new($list_store); my $renderer = Gtk2::CellRendererText->new; $renderer->set (xpad => 0, xalign => 0); # $renderer->set_fixed_size (150, 40); $combo_box->pack_start ($renderer, TRUE); $combo_box->add_attribute ($renderer, text => 0); my $renderer1 = Gtk2::CellRendererPixbuf->new; $renderer1->set (xpad => 0, xalign => 0); # $renderer->set_fixed_size (35, 40); $combo_box->pack_start ($renderer1, FALSE); $combo_box->add_attribute ($renderer1, pixbuf => 1); $combo_box->set_wrap_width (3); $combo_box->signal_connect('changed' => sub { my ($combo_box) = @_; my $iter = $combo_box->get_active_iter; print 'iter-> ',$combo_box->get_active_iter,"\n"; print 'index-> ',$combo_box->get_active,"\n"; print 'text-> ', $combo_box->get_active_text."\n"; print "\n"; }); $combo_box->set_active(0); $vbox->pack_start($combo_box,TRUE,TRUE,0); $vbox->show_all(); return $vbox; } ###################################### sub build_bunnies{ #basic black rgb = 0,0,0 my $bunny_b = decode_base64( 'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAjCAYAAACD1LrRAAAABmJLR0QA/wD/AP+gvaeTA +AAACXBI WXMAAAsSAAALEgHS3X78AAAAmElEQVRYw+1WQQ7AIAizxP9/mV121Gm0BZfYxNukKxSwlI +Pg75HG MrGALkykfHjPBKmf+tbIAad/0Ngp3CHGIrnvEoco7xFDTf6lGMIeH6YaBNVYrTEUKYfYUG +DW0bOI t2qrTjVYNXa2f9SDAqt97I1AlMFST9pOIbjEYRuKsSS4fUZydcqSQOTzVubq/w+QmmVWtm +IvFx08 tNghLUXwK/sAAAAASUVORK5CYII='); my $bunny; my $img = Imager->new; $img->read(data=>$bunny_b, type=>'png') or die "Cannot read: ", $img->errstr; my @rgbs = ( [0,0,0], [127,127,127], [255,255,255], [255,0,0], [178,0,178], [255,0,255], [0,255,0], [255,255,0],[255,127,0], [0,0,255],[0,255,255],[145,145,0], ); my $count = -1; foreach my $tref( @rgbs ){ $count++; my $newimg = $img->copy(); my($r,$g,$b) = @{$tref}; print "$r $g $b\n"; my $new_color = Imager::Color->new($r, $g, $b, 255 ); $newimg->flood_fill(x=>15, y=>15, color=>$new_color); #$newimg->filter(type=>'contrast', intensity=> $c); $newimg->write( data => \$bunny, type=>'png' ); # this properly renders it to pixbuf $bunnies{$count} = do { my $loader = Gtk2::Gdk::PixbufLoader->new(); $loader->write( $bunny ); $loader->close(); $loader->get_pixbuf(); }; } print "count -> $count\n"; } ######################################
In reply to Re^4: Multi-column Tk:Optionmenu?
by zentara
in thread Multi-column Tk:Optionmenu?
by BernieC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |