Hidetoshi NAGAI wrote:
> 
> Try this.
> ----------------------------------------------------------------------------
> require 'tk'
> 
> TkLabel.new(:text=>'click me!', :padx=>10, :pady=>5, :relief=>:raised){
>   place(:x=>30, :y=>50)
> 
>   bind('1', proc{|x, y|
>          p info = self.place_info
>          p [[x, y], [info['x'], info['y']], [info['x'] + x, info['y'] + 
> y]]
>        }, '%x %y')
> }
> 
> Tk.mainloop


 YES!!!   YES!!!   YES!!!   That worked!

When I click in the sudoku cell (TkcRectangle) just above the number 
(TkLabel), I get:

tell_it: Mouse button 1 clicked at coordinates (124,71)

When I click the number (TkLabel), I get:

{"relwidth"=>"", "relx"=>0, "x"=>115, "anchor"=>"nw", "y"=>75, 
"relheight"=>"", "rely"=>0, "height"=>20
, "width"=>20}
[[7, 4], [115, 75], [122, 79]]

So, the "[info['x'] + x, info['y'] + y]" is just what I needed.  The 
coordinates [122, 79] map to the proper cell!  Thank you, Hidetoshi. 
Thank you very much!

I now (or will soon, after I integrate this technique) have a playable 
sudoku game!  (:>)

My development plan was to proceed in three steps.  Step 1 was to draw 
the board, outline any clicked cell with the left-click, and highlight 
the cell's constraining row, columnn and sub-grid with the the 
right-click.  Step 2 was to enter numbers constrained by the rules of 
sudoku, generate a history of the moves, and to implement backing up 
through the history of the moves.

Completion of steps 1 and 2 would give me a "playable" sudoku game.  I 
am now at this point, thanks to you, my friend!

Step 3 will be to implement inputting a game's initial configuration 
from a file, generating games of varying difficulty, and solving the 
game via a set of hints that allow progressively advanced solution 
strategies, starting with basic ones such as 'intersections' and 'forced 
moves', and up through the use of advanced techniques such as 'x-wing' 
and 'unique rectangles'.

I realize that an argument can be made for completing the logic first 
and doing the GUI last, but I figured that this way I could acquire more 
Ruby syntax and semantics up front.  Learning Ruby, after all, was the 
reason why I started this this project to begin with.

So, I thank you again.  When the code is a bit more robust, I'll send 
you a copy.



-- 
Posted via http://www.ruby-forum.com/.