# Ruby tkentry tkvariable with class wrappers problem

**URL:** <https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673>\
**Category:** Ruby\
**Created:** [March 23, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673 "2009-03-23T20:46:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![branco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@branco](https://www.ruby-forum.com/u/branco)\
**Post date:** [March 23, 2009, 8:46pm UTC](https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673/1 "2009-03-23T20:46:04Z")

</div>

I try to create a tkEntry with a tkVariable attached in the class  
startupinterface and create a callback to startupinterfacecontroller but  
it doesn’t work : it says that themember variable supposed to hold a  
link to the tkVariable object is nil:nilClass when i try to call the  
value member function

code is in attachement

any help appreciated

---

<div class="post-metadata">

**Author:** ![branco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@branco](https://www.ruby-forum.com/u/branco)\
**Post date:** [March 23, 2009, 9:21pm UTC](https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673/2 "2009-03-23T21:21:26Z")

</div>

From: Cristian A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: ruby tkentry tkvariable with class wrappers problem  
Date: Tue, 24 Mar 2009 04:43:01 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> it doesn’t work : it says that themember variable supposed to hold a  
> link to the tkVariable object is nil:nilClass when i try to call the  
> value member function

Hmmm…  
You may be misunderstanding about a block given to .new.

# And, your code has a problem about accessing a TkVariable object.

* * *

## @files\_lcoation\_text=TkVariable.new @files\_location\_text=“” @files\_location\_entry=TkEntry.new(tk\_root){ textvariable @files\_location\_text }.grid(“row”=\>0 , “column”=\>1) @files\_location\_text=“tada”

Such block is evaluated with “instance\_eval”.  
That is, at internal of the block, “self” is the widget created by  
“new” method. So, @files\_location\_text in the block is a instance  
variable of the entry widget.

There are two ways to avoid this problem.  
The one is to use a local variable.  
And another is to use a Hash argument.

## -----\<case.1\>---------------------------------------------- @files\_lcoation\_text = txt\_var = TkVariable.new(“”) @files\_location\_entry=TkEntry.new(tk\_root){ textvariable txt\_var }.grid(“row”=\>0 , “column”=\>1) @files\_location\_text.value = “tada”

## -----\<case.2\>---------------------------------------------- @files\_lcoation\_text = TkVariable.new(“”) @files\_location\_entry=TkEntry.new(tk\_root, :textvariable=\>@files\_lcoation\_text).grid(:row=\>0 , :column=\>1) @files\_location\_text.value = “tada”

Please take attention to a scope of a variable.

---

<div class="post-metadata">

**Author:** ![branco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@branco](https://www.ruby-forum.com/u/branco)\
**Post date:** [March 23, 2009, 10:07pm UTC](https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673/3 "2009-03-23T22:07:45Z")

</div>

problem solved ; thanks for the help

---

<div class="post-metadata">

**Author:** ![branco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@branco](https://www.ruby-forum.com/u/branco)\
**Post date:** [March 23, 2009, 11:03pm UTC](https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673/4 "2009-03-23T23:03:26Z")

</div>

the fix is good but i hit another problem

when I try to change the value of the tkvariable member variable with  
the value member function of tkvariable it doesn’t work : it says  
nil:NilClass when pressing the button change\_entry\_text

I try to change the value of the initial entry/tkvariable by using the  
value of a new one or possibly the value supplied by any external class  
that has a reference

new code version is attached

---

<div class="post-metadata">

**Author:** ![branco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@branco](https://www.ruby-forum.com/u/branco)\
**Post date:** [March 24, 2009, 4:30am UTC](https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673/5 "2009-03-24T04:30:24Z")

</div>

that fixed it again hope i’ll be more carefull next time and not post  
typo questions

---

<div class="post-metadata">

**Author:** ![branco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@branco](https://www.ruby-forum.com/u/branco)\
**Post date:** [March 24, 2009, 3:42am UTC](https://www.ruby-forum.com/t/ruby-tkentry-tkvariable-with-class-wrappers-problem/163673/6 "2009-03-24T03:42:06Z")

</div>

From: Cristian A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: ruby tkentry tkvariable with class wrappers problem  
Date: Tue, 24 Mar 2009 07:00:24 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> when I try to change the value of the tkvariable member variable with  
> the value member function of tkvariable it doesn’t work : it says  
> nil:NilClass when pressing the button change\_entry\_text

It’s a typo.

— chess\_games\_helper.rb.orig 2009-03-24 11:38:46.000000000 +0900  
+++ chess\_games\_helper.rb 2009-03-24 11:40:03.000000000 +0900  
@@ -51,7 +51,7 @@  
files\_location\_entry\_d.insert(‘end’ , “data files  
location”)  
files\_location\_entry\_d.state=“disabled”

- 

```
          @files_lcoation_text=txt_var=TkVariable.new

```

- 

```
          @files_location_text=txt_var=TkVariable.new

          new_txt=TkVariable.new
          files_location_entry=TkEntry.new(tk_root){

```
