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

Edit : Never mind, I solve this with a $window->show_all; inside the callback sub.

hi, I am developping a Gtk3 application that uses a notebook (widget with tabs). I can't add a new page to the notebook (append_page) when calling from a signal callback sub (click on a button)

use strict; use warnings; use Glib 'TRUE', 'FALSE'; use Gtk3 -init; #new window and box my $window = Gtk3::Window->new ('toplevel'); my $box = Gtk3::Box->new( 'vertical', 0); my $notebook = Gtk3::Notebook->new(); # ----> works : append a new page in the notebook my $n = Gtk3::Label->new('TABNAME'); my $c = Gtk3::Label->new('TABCONTENT'); $notebook->append_page ($c, $n); my $btn = Gtk3::Button->new('Add page'); $btn->signal_connect('clicked' => sub { # ----> same code does nothing when called from a signal callback +sub my $n = Gtk3::Label->new('TABNAME'); my $c = Gtk3::Label->new('TABCONTENT'); $notebook->append_page ($c, $n); }); #add and show widgets $box->pack_start($notebook, TRUE, TRUE, 0); $box->add($btn); $box->set_size_request (500, 300); $window->add($box); $window->show_all; Gtk3::main;

the example code I've found never add a new tab from a callback but from hard coding this is gtk2 but whatever Any pointers is appreciated.

s

Replies are listed 'Best First'.
Re: Gtk3 notebook, append a page from a signal
by dave-theunsub (Scribe) on Jan 19, 2015 at 01:39 UTC
    You need a $notebook->show_all; after you append it. Note that that will *not* change to the tab - you'll have to add the code for that as well.