[wxruby-users] Tabs
David Peoples
davidp at touringcyclist.com
Mon Mar 16 14:03:05 EDT 2009
Trans wrote:
> Can anyone tell me how to create a tabbed interface? I tried using the
> Notebook control but I could not get it to work.
>
> I'm trying to put a Grid on one of the Notebook pages.
>
> Thanks,
> Trans
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users
It is fairly straightforward. I think the key is to attach the controls
to Wx::Panels, then add the panels to the notebook. See the sample code
below.
#!/usr/bin/env ruby
require 'wx'
include Wx
class MainFrame < Frame
def initialize(title)
super(nil, :title => title)
panel_1 = Panel.new(self)
box_1 = BoxSizer.new(VERTICAL)
panel_1.sizer = box_1
notebook = Notebook.new(panel_1, :style => NB_TOP)
box_1.add(notebook, 0, ALIGN_LEFT | ALL, 10)
panel_n1 = Panel.new(notebook)
box_n1 = BoxSizer.new(VERTICAL)
panel_n1.sizer = box_n1
box_n1.add(TextCtrl.new(panel_n1), 0, ALIGN_LEFT | ALL, 10)
box_n1.add(TextCtrl.new(panel_n1), 0, ALIGN_LEFT | ALL, 10)
panel_n2 = Panel.new(notebook)
box_n2 = BoxSizer.new(VERTICAL)
panel_n2.sizer = box_n2
grid_n2 = Grid.new(panel_n2, :size => [270, 140])
grid_n2.create_grid(3,2)
box_n2.add(grid_n2, 0, ALIGN_LEFT | ALL, 10)
notebook.add_page(panel_n1, "Tab 1", true)
notebook.add_page(panel_n2, "Tab 2", false)
end
end
Wx::App.run do
self.app_name = 'TestNotebook'
frame = MainFrame.new("Test notebook")
frame.show
end
--
David Peoples davidp at touringcyclist.com
The Touring Cyclist http://www.touringcyclist.com
11816 St. Charles Rock Road, Bridgeton, MO 63044
tel: 314-739-4648 fax: 314-739-4972
More information about the wxruby-users
mailing list