# Wxruby and the use of sizers - Help, Please!

**URL:** <https://www.ruby-forum.com/t/wxruby-and-the-use-of-sizers-help-please/158502>\
**Category:** Ruby\
**Created:** [January 23, 2009, 11:43pm UTC](https://www.ruby-forum.com/t/wxruby-and-the-use-of-sizers-help-please/158502 "2009-01-23T23:43:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rubina](https://www.ruby-forum.com/u/rubina)\
**Post date:** [January 23, 2009, 11:43pm UTC](https://www.ruby-forum.com/t/wxruby-and-the-use-of-sizers-help-please/158502/1 "2009-01-23T23:43:33Z")

</div>

Hello all you happy people!  
I am trying to learn wxruby and to that effect I played with the  
tutorial,  
which is very limited.  
I am trying to draw a grid for a sudoku puzzle. I first tried using  
GridSizer but then I did not know how to add each cell (button) to the  
9x9  
grid.  
Then I thought that perhaps I should use GridBagSizer for flexibility or  
something else.  
I need to be able to change the caption of the button, which could have  
a  
number from 1 to 9, dynamically.  
Which class should I use and where can I find examples of it uses?  
I searched Google with different search keys but could not really find  
any  
example.

Your help will be greatly appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![rubina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rubina](https://www.ruby-forum.com/u/rubina)\
**Post date:** [January 24, 2009, 1:40am UTC](https://www.ruby-forum.com/t/wxruby-and-the-use-of-sizers-help-please/158502/2 "2009-01-24T01:40:41Z")

</div>

Ruby S. wrote:

> I am trying to learn wxruby and to that effect I played with the tutorial,  
> which is very limited.

Questions about wxRuby are more appropriate to the wxruby-users mailing  
list:  
[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)  
OR WEB ACCESS:  
[http://www.ruby-forum.com/forum/36](http://www.ruby-forum.com/forum/36)

If possible, show some example code with what you’ve tried and you will  
find people happy to advise.

> I am trying to draw a grid for a sudoku puzzle. I first tried using  
> GridSizer but then I did not know how to add each cell (button) to the 9x9  
> grid.

You create and add a button to a sizer with something like this:

sizer = Wx::GridSizer.new(9) # 9 column  
button = Wx::Button.new(parent, :label =\> ‘3’)  
sizer.add(sudoku\_button)

> Then I thought that perhaps I should use GridBagSizer for flexibility or  
> something else.

Probably not GridBagSizer. It’s offered b/c it’s part of the wxWidgets  
API, but there are almost always easier and simpler ways of doing the  
same thing, IMHO.

> I need to be able to change the caption of the button, which could have a  
> number from 1 to 9, dynamically.

No problem:

button.label = “4”

> Which class should I use and where can I find examples of it uses?

You could use GridSizer + Buttons, as you have been. Simple, but it  
might look a bit strange.

You could use Wx::Grid, a spreadsheet-style widget.

A bit more work, but probably the most attractive solution: you could  
draw your own grid lines and numbers using a DC (Device Context).

You will find examples of using all of these by looking in the samples  
distributed with the wxRuby gem / source. Look in samples/grid,  
samples/bigdemo/wxSizer and samples/drawing for help.

a

---

<div class="post-metadata">

**Author:** ![rubina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rubina](https://www.ruby-forum.com/u/rubina)\
**Post date:** [January 24, 2009, 2:46am UTC](https://www.ruby-forum.com/t/wxruby-and-the-use-of-sizers-help-please/158502/3 "2009-01-24T02:46:46Z")

</div>

Alex, thank you for your quick and detailed reply.I will look at the  
samples  
distributed with wx.

Thank you

Ruby S.
