ruby – 如何在运行时将页面添加到Gtk Notebook小部件?
发布时间:2020-12-17 03:08:19 所属栏目:百科 来源:网络整理
导读:我有以下代码: require "gtk2"# adds a page to the notebook with the given labeldef create_page(nb,label="untitled") # create a textview tx = Gtk::TextView.new # append it nb.append_page(tx,Gtk::Label.new(label))endGtk.initwindow = Gtk::Win
我有以下代码:
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,0) create_page(notebook) container.pack_start(notebook,true,0) window.add(container) window.show_all Gtk.main 基本上,它是一个包含按钮和笔记本小部件的窗口.我希望能够在按下按钮时向笔记本小部件添加新的页面/选项卡.然而,没有任何反应.我应该手动做某种重复吗?我在滥用笔记本小部件吗?如何在运行时添加选项卡? 解决方法
通过替换这个:
button.signal_connect("clicked") { create_page(notebook) } 有了这个: button.signal_connect("clicked") { create_page(notebook) notebook.show_all } 新添加的标签/页面变得可见. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |