Guest User

Untitled

a guest
Jul 15th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/ruby
  2.  
  3. module TkPainter
  4.     require 'tk'
  5.  
  6.     ROOT = TkRoot.new { title "Tk Ruby Application"}
  7.  
  8. end
  9.  
  10. class Button < TkButton
  11.     include TkPainter
  12.     attr_accessor   :name, :action
  13.  
  14.     def initialize(p_name, p_action)
  15.         super(TkPainter::ROOT, 'text' => p_name, 'command' => p_action )
  16.         @name = p_name
  17.         @action = p_action
  18.     end
  19.  
  20.     def draw
  21.         self.pack('side' => 'left')
  22.     end
  23. end
  24.  
  25. say_hello = proc { puts "hello" }
  26. say_goodbye = proc { puts "goodbye" }  
  27.  
  28. b1 = Button.new("Say hello", say_hello)
  29. b2 = Button.new("Say goodbye", say_goodbye)
  30.  
  31. b1.draw
  32. b2.draw
  33.  
  34. Tk.mainloop
Advertisement
Add Comment
Please, Sign In to add comment