Re: Tooltips with labels



On Thu, 7 Dec 2006 18:26:36 +0530
"Ashwin Ramachandran" <rashwin28 gmail com> wrote:

Just wanted to check if tooltips are supported with label widgets?

Here is a simple example.
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

my $window = Gtk2::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(300,200);

my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);
$hbox->set_border_width(2);

my $frame0 = Gtk2::Frame->new('Controls');
$vbox->pack_end( $frame0, FALSE, FALSE, 0 );
$frame0->set_border_width(3);

$vbox->pack_end (Gtk2::HSeparator->new, FALSE, FALSE, 0);

my $hbox0 = Gtk2::HBox->new( FALSE, 6 );
$frame0->add($hbox0);
$hbox0->set_border_width(3);

my $button = Gtk2::Button->new_from_stock('gtk-quit');
$hbox0->pack_end( $button, FALSE, FALSE, 0 );
$button->signal_connect( clicked => \&delete_event );

my $frame1 = Gtk2::Frame->new('Some Frame');
$vbox->pack_start( $frame1, FALSE, FALSE, 0 );
$frame1->set_border_width(3);


#labels don't respond to tooltips, since they have no
#underlying window, so we must put the label in an event box.
my $label =  Gtk2::Label->new( "This label is just for you\n" );
$label->set_justify('left');

my $eventb1 = Gtk2::EventBox->new();
$eventb1->set_border_width(3);
$eventb1->add($label);

$frame1->add($eventb1);

my $tooltip0 = Gtk2::Tooltips->new;
my $tip_text = 'Just for you';
$tooltip0->set_tip($eventb1, $tip_text, undef);

my $tooltip1 = Gtk2::Tooltips->new;
my $tip_text1 = 'Just Another Exit Button';
$tooltip1->set_tip($button, $tip_text1, undef);


$window->show_all();
Gtk2->main;
#####################################
sub delete_event {
Gtk2->main_quit;
return FALSE;
}  



-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]