[英]How can I 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, it's a window containing a button and a notebook widget.基本上,它是一个 window 包含一个按钮和一个笔记本小部件。 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?
如何在运行时添加选项卡?
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.新添加的选项卡/页面变得可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.