How to add a page to a Gtk Notebook widget at runtime?

I have the following code:

require "gtk2" # adds a page to the notebook with the given label def create_page(nb,label="untitled") # create a textview tx = Gtk::TextView.new # append it nb.append_page(tx,Gtk::Label.new(label)) end Gtk.init window = Gtk::Window.new window.set_default_size(800,600) window.signal_connect("destroy") { Gtk.main_quit } container = Gtk::VBox.new notebook = Gtk::Notebook.new button = Gtk::Button.new("New") # when I push the button, I want a new page to be added button.signal_connect("clicked") { create_page(notebook) } container.pack_start(button,false,false,0) create_page(notebook) container.pack_start(notebook,true,true,0) window.add(container) window.show_all Gtk.main 

Basically, this is a window containing a button and widget for a laptop. I want to add a new page / tab to a laptop widget when I press a button. However, nothing happens. Is there some kind of repainting that I have to do manually? Am I abusing laptop widgets? How to add tab at runtime?

+4
source share
1 answer

Replacing this:

 button.signal_connect("clicked") { create_page(notebook) } 

with this:

 button.signal_connect("clicked") { create_page(notebook) notebook.show_all } 

new tabs / pages appear.

+7
source

All Articles