How do I organize widgets in a form when I need them placed in more than
a single column or row? I leaned how to use BoxSizer and successfully
displayed my widgets in a single column but can’t get the next column.
Here is my code, which puts a text, radio, button all in one column, but
what if I wanted my radios over to the right?:
require “rubygems”
require “wx”
include Wx
class MyFrame < Frame
def initialize
super(nil, :title => “My Test Frame”)
@panel = Panel.new(self)
@result = StaticText.new(@panel, :label=>'Result')
@y = TextCtrl.new(@panel, -1, '10')
shape_choice = %w(Circular Rectangular Trapezoidal )
submit_button = Button.new(@panel, :label => 'Calculate')
my_radio = RadioBox.new(
@panel,
:label => "Select Conduit Shape",
:choices => shape_choice,
:major_dimension => 1
)
@panel_sizer = BoxSizer.new(VERTICAL)
@panel.set_sizer(@panel_sizer)
@panel_sizer.add(@y, 0, GROW|ALL, 2)
@panel_sizer.add(my_radio, 0, GROW|ALL, 2)
@panel_sizer.add(submit_button, 0, GROW|ALL, 2)
@panel_sizer.add(@result, 0, GROW|ALL, 2)
evt_button(submit_button.get_id()) {|cmd_event|
on_submit(cmd_event)}
evt_radiobox(my_radio.get_id()) {|cmd_event|
on_change_radio(cmd_event)}
show()
end
def on_change_radio(cmd_event)
@selected_shape = cmd_event.string
end
def on_submit(cmd_event)
y = @y.get_value().to_f
area = case
when @selected_shape == ‘Circular’ then Math::PI * y**2 / 4.0
when @selected_shape == ‘Rectangular’ then y * 5.0
else (5.0 + 2.0 * y) * y
end
@result.label = "#{area} square feet"
end
end
class MinimalApp < App
def on_init
MyFrame.new
end
end
MinimalApp.new.main_loop