Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- module TkPainter
- require 'tk'
- ROOT = TkRoot.new { title "Tk Ruby Application"}
- end
- class Button < TkButton
- include TkPainter
- attr_accessor :name, :action
- def initialize(p_name, &p_action)
- super(TkPainter::ROOT, 'text' => p_name, 'command' => p_action )
- @name = p_name
- @action = p_action
- end
- def draw
- self.pack('side' => 'left')
- end
- end
- say_hello = lambda { puts "hello" }
- say_goodbye = lambda { puts "goodbye" }
- b1 = Button.new("Say hello", &say_hello)
- b2 = Button.new("Say goodbye", &say_goodbye)
- b1.draw
- b2.draw
- Tk.mainloop
- # Outputs "hello" and "goodbye" before pushing the buttons, how to avoid it ?
Advertisement
Add Comment
Please, Sign In to add comment