# Help understanding EVERYTHING

**URL:** <https://www.ruby-forum.com/t/help-understanding-everything/158956>\
**Category:** wxRuby\
**Created:** [January 29, 2009, 7:30pm UTC](https://www.ruby-forum.com/t/help-understanding-everything/158956 "2009-01-29T19:30:05Z")\
**Posts on this page:** 5\
**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 29, 2009, 7:30pm UTC](https://www.ruby-forum.com/t/help-understanding-everything/158956/1 "2009-01-29T19:30:05Z")

</div>

Team,

I am trying to learn a GUI for Ruby and I picked wxRuby.  
The problem is that I am kind of slow learning this and I now feel  
frustrated after trying for about at least 7 hours.  
I am trying to design a simple Sudoku 9x9 grid to display numbers, 1 -  
9,  
using buttons.  
I posted a question on Ruby forum ruby-talk and a gentleman, Alex  
Fenton,  
answered my questions.  
Alex gave me what appear to be great hints. However, as I said earlier,  
I am  
kind of slow and learn by example.  
I tried reading the bigdemo that comes with wxruby and looked on RDOC  
and  
google, but can’t find any help.  
Alex suggested to use this forum to get help.

I don’t want you to provide me with a solution but I need some solid  
hints,  
if you have the time and will not mind helping me.

I am including a code that I am using to play and learn wxruby. Please  
take  
a look at it and see if you can tell me why I can’t display all the  
buttons  
a defined. Only the first button, 1, is displayed.  
Once I get those working I will be able to add the rest. The total for a  
“normal” Sudoku puzzle is 81 for the 9x9 grid.

Thank you very much for your help.

PS: Is there a wxruby book that I can purchase?

---

<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 29, 2009, 9:35pm UTC](https://www.ruby-forum.com/t/help-understanding-everything/158956/2 "2009-01-29T21:35:58Z")

</div>

Your message does not have any code attached. Might want to repost  
with the attachment.

Sean

---

<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 30, 2009, 11:26pm UTC](https://www.ruby-forum.com/t/help-understanding-everything/158956/3 "2009-01-30T23:26:45Z")

</div>

Your problem was adding a sizer to the panel and then adding the  
GridSizer to that sizer.

I automated your button generation for kicks.

Try this

Sean

begin  
require ‘rubygems’  
rescue LoadError  
end

require ‘wx’  
include Wx

class MyFrame \< Frame  
def initialize()  
# One can use the following, commented version or the next 2  
#Frame.new(nil, -1, “Sudoku Puzzle”).show()  
super(nil, -1, ‘Sudoku Puzzle’, Point.new(220,100),  
Size.new(600,480))  
@mp = Panel.new(self)

```
# GridSizer.new(Integer rows, Integer cols, Integer vgap, Integer 

```

hgap)  
gs = GridSizer.new(9, 9, 2, 2) # My goal is to define a sudoku grid  
9x9

```
@buttons = Array.new(9)
@buttons.each_index do |i|
  @buttons[i] = Array.new(9)
end

id = 0
(0..8).to_a.each do |x|
  (0..8).to_a.each do |y|
    b = Button.new(@mp,id,:label=>id.to_s)
    @buttons[x][y] = b
    gs.add(b)
    evt_button(id) {|event| button_click(event)}
    id += 1
  end
end

main_sizer = Wx::BoxSizer.new(Wx::VERTICAL)
main_sizer.add(gs,1,Wx::ALL|Wx::GROW,5)
@mp.set_sizer(main_sizer)

show()

```

end # initialize

def button\_click(event)  
# code here  
end

end # MyFrame Class

class MyApp3 \< App  
def on\_init  
MyFrame.new  
end # on\_init  
end # MyApp3

##### 

MyApp3.new.main\_loop

---

<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 30, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/help-understanding-everything/158956/4 "2009-01-30T16:47:33Z")

</div>

On Thu, Jan 29, 2009 at 3:32 PM, Sean L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > The problem is that I am kind of slow learning this and I now feel  
> > Alex suggested to use this forum to get help.  
> > Once I get those working I will be able to add the rest. The total for a  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)
> 
> * * *
> 
> wxruby-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Sorry about that. Here it is:

begin  
require ‘rubygems’  
rescue LoadError  
end

require ‘wx’  
include Wx

class MyFrame \< Frame  
def initialize()  
# One can use the following, commented version or the next 2  
#Frame.new(nil, -1, “Sudoku Puzzle”).show()  
super(nil, -1, ‘Sudoku Puzzle’, Point.new(220,100),  
Size.new(600,480))  
@mp = Panel.new(self)

```
# GridSizer.new(Integer rows, Integer cols, Integer vgap, Integer

```

hgap)  
gs = GridSizer.new(9, 9, 2, 2) # My goal is to define a sudoku grid  
9x9

=begin  
Button.new(Window parent, Integer id, String label = ‘’,  
Point pos = DEFAULT\_POSITION,  
Size size = DEFAULT\_SIZE,  
Integer style = 0,  
Validator validator = DEFAULT\_VALIDATOR,  
String name = “button”)  
=end

@b1 = Button.new(@mp, 1, :label=\> ‘1’)  
gs.add(@b1)  
evt\_button(@b1.get\_id()) { |event| button\_click(event)}

@b2 = Button.new(@mp, 2, :label=\>‘2’)  
gs.add(@b2)  
evt\_button(@b2.get\_id()) { |event| button\_click(event)}

@b3 = Button.new(@mp, 3, :label=\> ‘3’)  
gs.add(@b3)  
evt\_button(@b3.get\_id()) { |event| button\_click(event)}

@b4 = Button.new(@mp, 4, :label=\>‘4’)  
gs.add(@b4)  
evt\_button(@b4.get\_id()) { |event| button\_click(event)}

###### Etc, Etc …until placing button located on cell [9][9]

```
show()

```

end # initialize

```
  def button_click(event)
  # code here
  end

```

end # MyFrame Class

class MyApp3 \< App  
def on\_init  
MyFrame.new  
end # on\_init  
end # MyApp3

##### 

MyApp3.new.main\_loop

---

<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 31, 2009, 5:58pm UTC](https://www.ruby-forum.com/t/help-understanding-everything/158956/5 "2009-01-31T17:58:52Z")

</div>

On Fri, Jan 30, 2009 at 4:36 PM, Sean L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> require ‘rubygems’  
> super(nil, -1, ‘Sudoku Puzzle’, Point.new(220,100), Size.new(600,480))
> 
> MyApp3.new.main\_loop
> 
> > > > ## The problem is that I am kind of slow learning this and I now feel kind of slow and learn by example. take
> > > 
> > > [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)
> > 
> > ```
> > gs = GridSizer.new(9, 9, 2, 2) # My goal is to define a sudoku grid
> > 
> > ```
> > 
> > gs.add(@b1)  
> > @b4 = Button.new(@mp, 4, :label=\>‘4’)  
> > end  
> > MyApp3.new.main\_loop  
> > wxruby-users mailing list  
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Sean,  
Thank you for your help. Perhaps one day I’ll be able to help someone  
else.
