我有以下代码:
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
基本上,它是一个包含一个按钮和一个notebook小部件的窗口。我希望当我按下按钮时能够向notebook小部件添加新的页面/选项卡。但是,什么也不会发生。有没有我应该手动重绘的东西?我是否误用了notebook小部件?如何在运行时添加选项卡?
发布于 2009-03-23 09:03:33
通过替换以下内容:
button.signal_connect("clicked") {
create_page(notebook)
}
有了这个:
button.signal_connect("clicked") {
create_page(notebook)
notebook.show_all
}
新添加的选项卡/页面将变为可见。
https://stackoverflow.com/questions/674195
复制