Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This script displays a Gtk2::Notebook with several tabs.

The tab labels are actually quite big - there's a lot of empty space above and below the words 'Hello world'. Vertical space is at a premium, and I would prefer the tab labels to be about half the height that they actually are.

Is there any way in which I can reduce the empty space above and below the words 'Hello world'?

#!/usr/bin/perl package biglabel; use strict; use diagnostics; use warnings; use Gtk2 '-init'; use Glib qw(TRUE FALSE); # Create the window my $window = Gtk2::Window->new(); $window->set_title('Notebook'); $window->set_position('center'); $window->set_default_size(800, 500); $window->set_border_width(5); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); # Add a VBox with a VPaned, containing a notebook at the top and an en +try at the bottom my $vBox = Gtk2::VBox->new(FALSE, 0); my $vPaned = Gtk2::VPaned->new(); $vPaned->set_position(400); $vBox->pack_start($vPaned, TRUE, TRUE, 0); my $noteBook = Gtk2::Notebook->new(); $noteBook->set_scrollable(TRUE); $noteBook->can_focus(FALSE); $vPaned->add($noteBook); my $entry = Gtk2::Entry->new(); $entry->can_focus(TRUE); $vPaned->add2($entry); # Add three tabs to the notebook for (my $num = 0; $num < 3; $num++) { my ($buffer, $tabNum) = openTab($noteBook); } # Open the window $window->add($vBox); $window->show_all(); Gtk2->main(); #################### sub openTab { # Create a tab in the notebook, containing a textview my ($noteBook) = @_; # The vertical packing box contains only a textview my $vBox = Gtk2::VBox->new(FALSE, 0); # The horizontal packing box is used as the tab's label (in pl +ace of a Gtk2::Label) my $hBox = Gtk2::HBox->new(FALSE, 0); my $label = Gtk2::Label->new('Hello world'); $hBox->pack_start($label, FALSE, FALSE, 0); my $button = Gtk2::Button->new(); $button->set_image(Gtk2::Image->new_from_stock('gtk-close', 'b +utton')); $button->set_relief('none'); $button->signal_connect (clicked => sub { # (Do nothing special) }); $hBox->pack_start($button, FALSE, FALSE, 0); $label->show(); $button->show(); my $tabNum = $noteBook->append_page($vBox, $hBox); # Add a textview to the tab my $frame = Gtk2::Frame->new(undef); $frame->set_border_width(0); my $scroll = Gtk2::ScrolledWindow->new(undef, undef); $scroll->set_shadow_type('etched-out'); $scroll->set_policy('automatic', 'automatic'); $scroll->set_border_width(0); my $textView = Gtk2::TextView->new(); my $buffer = Gtk2::TextBuffer->new(); $textView->set_buffer($buffer); $textView->set_editable(FALSE); $textView->set_cursor_visible(FALSE); # Invisible cursor $textView->can_focus(FALSE); $textView->set_wrap_mode('word-char'); # Wrap words if possib +le, characters if not $textView->set_justification('left'); $scroll->add($textView); $frame->add($scroll); $vBox->pack_start($frame, TRUE, TRUE, 0); $window->show_all(); # The new tab should be the visible (current) one $noteBook->set_current_page($tabNum); return ($buffer, $tabNum); }

Replies are listed 'Best First'.
Re: Gtk2::Notebook with large tabs
by thanos1983 (Parson) on May 27, 2015 at 23:57 UTC

    Hello Anonymous Monk,

    Since I am not familiar with Gtk2 I can not really help you. But I did not searched online and I came up with $notebook->set_tab_border ($border_width) I think this is probably what you are looking for. You can find other adjustments that you might be interested Gtk2::Notebook.

    Also if you have some time I would suggest to read also the new Perl module Gtk3s it has some extra features that you might be interested.

    Give it a try and reply to your question if you get more information(s) / solution(s), so other can benefit from.

    Any way as I said I have never used the module before so I hope my answer helped you or at least pointed you to the correct direction.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Hey thanos1983, thanks for your suggestion!

      It suddenly occured to me, while fiddling with ->set_tab_border(), that it might be the stock icon that was preventing the label from becoming smaller.

      Sure enough, removing the stock icon altogether reduces the tab's size dramatically. Using a smaller stock icon is also effective:

      $noteBook->set_tab_border(0); $button->set_image(Gtk2::Image->new_from_stock('gtk-close', 'menu'));
      Here's the corrected script:
      #!/usr/bin/perl package biglabel; use strict; use diagnostics; use warnings; use Gtk2 '-init'; use Glib qw(TRUE FALSE); # Create the window my $window = Gtk2::Window->new(); $window->set_title('Notebook'); $window->set_position('center'); $window->set_default_size(800, 500); $window->set_border_width(5); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); # Add a VBox with a VPaned, containing a notebook at the top and an en +try at the bottom my $vBox = Gtk2::VBox->new(FALSE, 0); my $vPaned = Gtk2::VPaned->new(); $vPaned->set_position(400); $vBox->pack_start($vPaned, TRUE, TRUE, 0); my $noteBook = Gtk2::Notebook->new(); $noteBook->set_scrollable(TRUE); $noteBook->can_focus(FALSE); $noteBook->set_tab_border(0); $vPaned->add($noteBook); my $entry = Gtk2::Entry->new(); $entry->can_focus(TRUE); $vPaned->add2($entry); # Add three tabs to the notebook for (my $num = 0; $num < 3; $num++) { my ($buffer, $tabNum) = openTab($noteBook); } # Open the window $window->add($vBox); $window->show_all(); Gtk2->main(); #################### sub openTab { # Create a tab in the notebook, containing a textview my ($noteBook) = @_; # The vertical packing box contains only a textview my $vBox = Gtk2::VBox->new(FALSE, 0); # The horizontal packing box is used as the tab's label (in pl +ace of a Gtk2::Label) my $hBox = Gtk2::HBox->new(FALSE, 0); my $label = Gtk2::Label->new('Hello world'); $hBox->pack_start($label, FALSE, FALSE, 0); my $button = Gtk2::Button->new(); $button->set_image(Gtk2::Image->new_from_stock('gtk-close', 'm +enu')); $button->set_relief('none'); $button->signal_connect (clicked => sub { # (Do nothing special) }); $hBox->pack_start($button, FALSE, FALSE, 0); $label->show(); $button->show(); my $tabNum = $noteBook->append_page($vBox, $hBox); # Add a textview to the tab my $frame = Gtk2::Frame->new(undef); $frame->set_border_width(0); my $scroll = Gtk2::ScrolledWindow->new(undef, undef); $scroll->set_shadow_type('etched-out'); $scroll->set_policy('automatic', 'automatic'); $scroll->set_border_width(0); my $textView = Gtk2::TextView->new(); my $buffer = Gtk2::TextBuffer->new(); $textView->set_buffer($buffer); $textView->set_editable(FALSE); $textView->set_cursor_visible(FALSE); # Invisible cursor $textView->can_focus(FALSE); $textView->set_wrap_mode('word-char'); # Wrap words if possib +le, characters if not $textView->set_justification('left'); $scroll->add($textView); $frame->add($scroll); $vBox->pack_start($frame, TRUE, TRUE, 0); $window->show_all(); # The new tab should be the visible (current) one $noteBook->set_current_page($tabNum); return ($buffer, $tabNum); }

        Hello Anonymous,

        I am glad that you got the answer to your question that you where looking for even through alternative solution. A different point of view is always good. Just keep on trying failing and happy coding... :D .

        Seeking for Perl wisdom...on the process of learning...not there...yet!