diff options
Diffstat (limited to 'sample/tkline.rb')
-rw-r--r-- | sample/tkline.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/sample/tkline.rb b/sample/tkline.rb new file mode 100644 index 0000000000..843893b5d9 --- /dev/null +++ b/sample/tkline.rb @@ -0,0 +1,29 @@ +require "tkclass" + +$c = Canvas.new +$c.pack +$start_x = start_y = 0 + +def do_press(x, y) + $start_x = x + $start_y = y + $current_line = Line.new($c, x, y, x, y, 'fill' => 'gray') +end +def do_motion(x, y) + if $current_line + $current_line.coords $start_x, $start_y, x, y + end +end + +def do_release(x, y) + if $current_line + $current_line.coords $start_x, $start_y, x, y + $current_line.fill 'black' + $current_line = nil + end +end + +$c.bind("1", proc{|e| do_press e.x,e.y}) +$c.bind("B1-Motion", proc{|e| do_motion e.x,e.y}) +$c.bind("ButtonRelease-1", proc{|e| do_release e.x,e.y}) +Tk.mainloop |