# Handling Events - Help

**URL:** <https://www.ruby-forum.com/t/handling-events-help/188830>\
**Category:** Ruby\
**Created:** [May 19, 2010, 2:19am UTC](https://www.ruby-forum.com/t/handling-events-help/188830 "2010-05-19T02:19:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![iroupa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c0e974/32.png) [@iroupa](https://www.ruby-forum.com/u/iroupa)\
**Post date:** [May 19, 2010, 2:19am UTC](https://www.ruby-forum.com/t/handling-events-help/188830/1 "2010-05-19T02:19:07Z")

</div>

Hi all,

I have crated a application with two TextCtrl boxes (One for write and  
the other to show the text that it’s written on the first box).

I try to use the “evt\_text() { | event | }” but when I run the  
application I have two problems:

When I press any key the application closes and I get this error:

C:/Program  
Files/Ruby19/lib/ruby/gems/1.9.1/gems/wxruby-ruby19-2.0.1-x86-mingw32/lib/wx/accessors.rb:50:in  
`method_missing': undefined local variable or method`text\_box\_2’ for  
#MyFrame:0x1242cc0 (NameError)  
from C:/Documentos/Ruby  
Scripts/Text\_Boxes/lib/Text\_Boxes.rb:38:in `block in initialize' from C:/Documentos/Ruby Scripts/Text_Boxes/lib/Text_Boxes.rb:50:in`call’  
from C:/Documentos/Ruby  
Scripts/Text\_Boxes/lib/Text\_Boxes.rb:50:in `process_event' from C:/Documentos/Ruby Scripts/Text_Boxes/lib/Text_Boxes.rb:50:in`process\_event’  
from C:/Documentos/Ruby  
Scripts/Text\_Boxes/lib/Text\_Boxes.rb:50:in `process_event' from C:/Documentos/Ruby Scripts/Text_Boxes/lib/Text_Boxes.rb:50:in`on\_run’  
from C:/Documentos/Ruby  
Scripts/Text\_Boxes/lib/Text\_Boxes.rb:50:in `main_loop' from C:/Documentos/Ruby Scripts/Text_Boxes/lib/Text_Boxes.rb:50:in`’

The second problem:

Since I’m a newbie I would like to know where can I find some help to  
understand events syntax…

Thanks in advance

Ivo R.

---

<div class="post-metadata">

**Author:** ![iroupa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c0e974/32.png) [@iroupa](https://www.ruby-forum.com/u/iroupa)\
**Post date:** [May 19, 2010, 9:07pm UTC](https://www.ruby-forum.com/t/handling-events-help/188830/2 "2010-05-19T21:07:16Z")

</div>

Could you post a sytax for this and i will see if i can help.

---

<div class="post-metadata">

**Author:** ![iroupa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c0e974/32.png) [@iroupa](https://www.ruby-forum.com/u/iroupa)\
**Post date:** [May 19, 2010, 9:07pm UTC](https://www.ruby-forum.com/t/handling-events-help/188830/3 "2010-05-19T21:07:22Z")

</div>

Could you post a sytax for this and I will see if I can help.

---

<div class="post-metadata">

**Author:** ![iroupa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c0e974/32.png) [@iroupa](https://www.ruby-forum.com/u/iroupa)\
**Post date:** [May 20, 2010, 2:57am UTC](https://www.ruby-forum.com/t/handling-events-help/188830/4 "2010-05-20T02:57:00Z")

</div>

Mark K.,

Now it’s almost working. I have been able to copy the content of  
text\_box\_1 to text\_box\_2 with the following code.

require ‘wx’  
include Wx

class MyFrame \< Wx::Frame  
def initialize  
super(nil,  
:id =\> -1,  
:pos =\> DEFAULT\_POSITION,  
:title =\> ‘EasyMacro’,  
:size =\> [900,600],  
:style =\> DEFAULT\_FRAME\_STYLE,  
:name =\> “Ivo”  
)

```
@panel = Wx::Panel.new(self)

@text_box_1 = Wx::TextCtrl.new(@panel,
         :id => 1,
         :value => "Write your text here",
         :pos => [0,50],
         :size => [400,500],
         :style => TE_PROCESS_ENTER ,
         :validator => DEFAULT_VALIDATOR,
         :name => 'TextCtrlNameStr_1'

```

)

```
@text_box_2 = Wx::TextCtrl.new(@panel,
         :id => 2,
         :value => "",
         :pos => [450,50],
         :size => [400,500],
         :style => TE_READONLY,
         :validator => DEFAULT_VALIDATOR,
         :name => 'TextCtrlNameStr_2'

```

)

evt\_text(@text\_box\_1.get\_id()) {|event| show\_text(event)}

```
show

```

end

def show\_text(event)  
text = @text\_box\_1.get\_value()  
@text\_box\_2.value = text  
end

end

class MinApp \< App  
def on\_init  
frame = MyFrame.new  
end  
end

MinApp.new.main\_loop

The only thing that I haven’t been able to do is to change line in  
text\_box\_1 when I click Enter… Or any other key…

If you can help me with that I would be very appreciated.

Thanks in advance

Ivo R.
