tags:

views:

362

answers:

1

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, it's a window containing a button and a notebook widget. I want to be able to add a new page/tab to the notebook widget when I press the button. However, nothing happens. Is there a repaint of some sort I should do manually? Am I misusing the notebook widget? How can I add a tab at runtime?

+1  A: 

By replacing this :


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

with this:


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

the newly added tabs/pages become visible.

Geo