# Tk and Tile with Tk8.5

**URL:** <https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262>\
**Category:** Ruby\
**Created:** [April 2, 2011, 2:45am UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262 "2011-04-02T02:45:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 2, 2011, 2:45am UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/1 "2011-04-02T02:45:21Z")

</div>

I want to use Ruby 1.9.1 (Ubuntu 10.10) with Tk8.5 Tile, but this samle  
code:

require ‘tk’  
require ‘tkextlib/tile’

root = TkRoot.new { title “Ex1” }

Tk::Tile::Button.new(root) {  
text “Ok”  
command proc { print “Hello, World!”; exit }  
pack(‘side’=\>‘left’, ‘padx’=\>10, ‘pady’=\>10)  
}

Tk.mainloop()

fails with:  
$ ruby tk\_test.rb  
/usr/lib/ruby/1.9.1/tkextlib/tile.rb:46:in `rescue in <top (required)>': undefined method` **cannot\_find\_tk\_package\_for\_widget\_set** ’ for  
Tk:Module (NoMethodError)  
from /usr/lib/ruby/1.9.1/tkextlib/tile.rb:31:in `<top (required)>' from <internal:lib/rubygems/custom_require>:29:in`require’  
from internal:lib/rubygems/custom\_require:29:in `require' from tk_test.rb:2:in`’

Googleing for “ **cannot\_find\_tk\_package\_for\_widget\_set** ” is one of  
those rare moments when Google gives back only 1 hit.  
Am I doing something wrong? I’m not a source code compiler type, I  
installed everything from aptitude (Ruby 1.9.1, Tk8.4, Tk8.5, Tcl8.4,  
Tcl8.5)

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 2, 2011, 5:40am UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/2 "2011-04-02T05:40:12Z")

</div>

Hi,

Thank you for your report.

From: Lszl F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Tk and Tile with Tk8.5  
Date: Sat, 2 Apr 2011 09:45:24 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I want to use Ruby 1.9.1 (Ubuntu 10.10) with Tk8.5 Tile, but this samle  
> code:  
> (snip)  
> fails with:  
> $ ruby tk\_test.rb  
> /usr/lib/ruby/1.9.1/tkextlib/tile.rb:46:in `rescue in <top (required)>': undefined method ` **cannot\_find\_tk\_package\_for\_widget\_set** ’ for  
> Tk:Module (NoMethodError)

I’m very sorry. It’s a bug which should be fixed.  
But it is not a primary problem for your trouble.  
If tile extension is installed (or Tcl/Tk is 8.5 or later),  
Ruby/Tk doesn’t use the bugged routine.

> Am I doing something wrong? I’m not a source code compiler type, I  
> installed everything from aptitude (Ruby 1.9.1, Tk8.4, Tk8.5, Tcl8.4,  
> Tcl8.5)

Probably, your ruby’s tcltklib.so is linked with Tcl/Tk8.4.  
Please check the result of ‘ruby -r tk -e “p Tk::TK\_PATCHLEVEL”’.  
If it shows 8.4.x, your tcltklib.so uses libraries of Tcl/Tk8.4.

To fix it, please install tile extension for your Tcl/Tk8.4,  
or re-compile your ruby’s tcltklib.so with Tcl/Tk8.5.  
I’m not familiar with Ubuntu. So, I don’t know which is better.  
If igonore it, I recommend you to re-compile tcltklib.so,  
because Tcl/Tk8.5 is better than Tcl/Tk8.4.

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 2, 2011, 11:37pm UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/3 "2011-04-02T23:37:42Z")

</div>

> Please check the result of ‘ruby -r tk -e “p Tk::TK\_PATCHLEVEL”’.  
> If it shows 8.4.x, your tcltklib.so uses libraries of Tcl/Tk8.4.

And indeed it is:  
$ ruby -r tk -e “p Tk::TK\_PATCHLEVEL”  
“8.4.19”

> or re-compile your ruby’s tcltklib.so with Tcl/Tk8.5.

Back to the “I’m not a source code compiler type”, can you give me some  
hint, how to do this? (not the ‘make install’ entry, but can it be  
independently recompiled from source or only together with other files  
or I need to recompile the whole Ruby package. And most importantly,  
what are the parameters that make it link to Tk8.5?)

Thanks

I tried to replace tcltklib.so with your  
tcltklib.so-tk8.5.7-ruby192dev\_20100313rev26900\_i686-linux but that .so  
introduced other unsatisfied dependencies (like libstdc++.so.5)

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 3, 2011, 1:58am UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/4 "2011-04-03T01:58:06Z")

</div>

From: Lszl F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Tk and Tile with Tk8.5  
Date: Sun, 3 Apr 2011 06:38:47 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > Please check the result of ‘ruby -r tk -e “p Tk::TK\_PATCHLEVEL”’.  
> > If it shows 8.4.x, your tcltklib.so uses libraries of Tcl/Tk8.4.
> 
> And indeed it is:  
> $ ruby -r tk -e “p Tk::TK\_PATCHLEVEL”  
> “8.4.19”

Are there tk-tile package for Tcl/Tk8.4 on Ubuntu 10.10 ?  
If it exists, please try to install the package.

> > or re-compile your ruby’s tcltklib.so with Tcl/Tk8.5.
> 
> Back to the “I’m not a source code compiler type”, can you give me some  
> hint, how to do this? (not the ‘make install’ entry, but can it be  
> independently recompiled from source or only together with other files  
> or I need to recompile the whole Ruby package. And most importantly,  
> what are the parameters that make it link to Tk8.5?)

First of all, I’m not familiar with Debian packages.  
So, I can’t tell you how to create your own Ruby/Tk package with  
Tcl/Tk8.5.

In general, extconf.rb of tcltklib (/ext/tk/extconf.rb)  
searches automatically the latest version of Tcl/Tk on the system.  
If you are luky ;-), you’ll be able to make a new ruby by  
“cd ; ./configure; make”.

# Of course, it requires Tcl/Tk dev packages.

Please check the messages of make steps.  
tcltklib’s extconf.rb shows the status of searching Tcl/Tk libraries.  
If it shows fail messages, you must give configure options.  
Please see \<ruby-src-dir/ext/tk/README.tcltklib. It describes  
configure options to teach position of Tcl/Tk libs to extconf.rb.  
Although there are many combinations of options to match several env,  
please try to give --with-tclConfig-file= and  
–with-tkConfig-file= at first.

If you have some trouble, please tell me the fail messages and the  
position of your Tcl/Tk headers and libraries.

> I tried to replace tcltklib.so with your  
> tcltklib.so-tk8.5.7-ruby192dev\_20100313rev26900\_i686-linux but that .so  
> introduced other unsatisfied dependencies (like libstdc++.so.5)

Sorry. It was compiled on an old environment (gcc-3.3).  
Even if it is available, I don’t recommnd partial replace of package  
files.  
It may break the package management system.

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 3, 2011, 4:30am UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/5 "2011-04-03T04:30:52Z")

</div>

László Földes wrote in post #990509:

> I want to use Ruby 1.9.1 (Ubuntu 10.10) with Tk8.5 Tile, but this samle  
> code:  
> […]  
> I’m not a source code compiler type, I  
> installed everything from aptitude (Ruby 1.9.1, Tk8.4, Tk8.5, Tcl8.4,  
> Tcl8.5)

Hi!

I’m using Ubuntu 10.04.1, but it probably isn’t different than yours.

You need install tile:

$ sudo apt-get install tk-tile

Note that Ruby will still use the ugly Tk 8.4. If you want it to use Tk  
8.5 (but you don’t have to), follow these steps:

[http://drx.rubyforge.org/ubuntu-new-tk.html](http://drx.rubyforge.org/ubuntu-new-tk.html)

BTW, your program works on my system: I tried it with both Tk 8.4 and Tk  
8.5 (I have a script that toggles between them).

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 3, 2011, 10:52pm UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/6 "2011-04-03T22:52:45Z")

</div>

Albert S. wrote in post #990613:

> [http://drx.rubyforge.org/ubuntu-new-tk.html](http://drx.rubyforge.org/ubuntu-new-tk.html)
> 
> BTW, your program works on my system: I tried it with both Tk 8.4 and Tk  
> 8.5 (I have a script that toggles between them).

Thanks, that solved it! (although the solution at the link has some  
serious überbug, although not irreparable).

Just for curiosity, how do you toggle between the two? As I saw it the  
Tk version is compiled into the tcltklib.so.

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 4, 2011, 2:57pm UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/7 "2011-04-04T14:57:29Z")

</div>

László Földes wrote in post #990721:

> Albert S. wrote in post #990613:
> 
> > [http://drx.rubyforge.org/ubuntu-new-tk.html](http://drx.rubyforge.org/ubuntu-new-tk.html)
> > 
> > BTW, your program works on my system: I tried it with both Tk 8.4 and Tk  
> > 8.5 (I have a script that toggles between them).
> 
> Thanks, that solved it! (although the solution at the link has some  
> serious überbug, although not irreparable).

What’s the “überbug”? Tell us, so that page (ubuntu-new-tk.html) could  
be fixed.

> Just for curiosity, how do you toggle between the two? As I saw it the  
> Tk version is compiled into the tcltklib.so.

Right. I copy the 8.4 version into “tcltklib.so.84”, and the 8.5 version  
into “tcltklib.so.85”, and my script simply copies the desired version  
into “tcltklib.so”. (To do this it uses the ‘sudo’ command because the  
/usr/lib/ruby/1.8/i486-linux/ directory is writable for root only.)

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 5, 2011, 12:16am UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/8 "2011-04-05T00:16:40Z")

</div>

From: Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Tk and Tile with Tk8.5  
Date: Mon, 4 Apr 2011 21:57:34 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > Just for curiosity, how do you toggle between the two? As I saw it the  
> > Tk version is compiled into the tcltklib.so.
> 
> Right. I copy the 8.4 version into “tcltklib.so.84”, and the 8.5 version  
> into “tcltklib.so.85”, and my script simply copies the desired version  
> into “tcltklib.so”. (To do this it uses the ‘sudo’ command because the  
> /usr/lib/ruby/1.8/i486-linux/ directory is writable for root only.)

The following depend on an unofficial feature of ruby’s dll loading.  
At present, it will work. But I don’t recomment it.

# I asked about the feature on ruby-dev ML. But I didn’t discuss it.

# Because I didn’t have enough time for discussion and I thought

# that there are not many people who requires such feature.

In the following, denotes ruby’s dll directory  
(.e.g /usr/lib/ruby/1.8/i486-linux).

(1) Copy the 8.4 version to /tcltklib.8.4.so, and the 8.5  
version to /tcltklib.8.5.so.  
Filenames must start by “tcltklib” + dot, and end by dot + “so”.  
For example, “tcltklib.84.so” or “tcltklib.8.4.19.so” is OK,  
but “tcltklib\_84.so” or “tcltklib.so.84” is NG.

(2) Create loader script “tcltklib.rb” at ruby’s library directory  
(.e.g /usr/lib/ruby/1.8).  
For example,  
----- tcltklib.rb -----------------------------------------  
ver = ENV[‘RUBYTK\_VERSION’]  
if ver && !ver.empty?  
require “tcltklib.#{ver}.so”  
else  
require “tcltklib.so”  
end  
-----------------------------------------------------------  
This exmaple selects the dll based on the environment variable.  
There are many way to decide the target dll.  
Please create your tcltklib.rb as you like.

(3) If you use tcltklib.rb at step (2),  
$ RUBYTK\_VERSION=8.4 ruby -r tk -e ‘p Tk::TK\_PATCHLEVEL’  
will use tcltklib.8.4.so (Tcl/Tk8.4 version), and  
$ RUBYTK\_VERSION=8.5 ruby -r tk -e ‘p Tk::TK\_PATCHLEVEL’  
will use tcltklib.8.5.so (Tcl/Tk8.5 version)

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 5, 2011, 10:43pm UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/9 "2011-04-05T22:43:42Z")

</div>

From: Albert S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Tk and Tile with Tk8.5  
Date: Tue, 5 Apr 2011 23:13:53 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > The following depend on an unofficial feature of ruby’s dll loading.  
> > At present, it will work. But I don’t recomment it.
> 
> BTW, what’s here isn’t an official feature? I do “ri Kernel#require” and  
> (I think) it describes everything needed to make this work: Ruby first  
> looks for an .rb file (this enables us to inject our loader script), and  
> then it’s possible to explicitly load a .so (or .dll). So why isn’t your  
> trick future-proof?

It depends on “how to find an entry point function of a DLL”.  
Ruby’s current DLL loader decides a name from a filename of DLL,  
that is, cuts a left most string from a DLL filename before first dot  
and links it after a string “Init\_”.  
So, for “tcltklib.so”, “tcltklib.84.so”, “tcltklib.8.5.9.so” and so  
on, the loader calls a function “Init\_tcltklib()”.  
But for “tcltklib\_84.so” (and others), the loader tries and fails to  
call a function “Init\_tcltklib\_84”.  
This is the reason of why a DLL filename is limitted on my trick.

The rule about “first dot” is NOT a specification of Ruby’s DLL loader.  
It may be changed in the future.

---

<div class="post-metadata">

**Author:** ![karatedog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@karatedog](https://www.ruby-forum.com/u/karatedog)\
**Post date:** [April 5, 2011, 4:13pm UTC](https://www.ruby-forum.com/t/tk-and-tile-with-tk8-5/205262/10 "2011-04-05T16:13:50Z")

</div>

Hidetoshi NAGAI wrote in post #990904:

> The following depend on an unofficial feature of ruby’s dll loading.  
> At present, it will work. But I don’t recomment it.  
> […]  
> (2) Create loader script “tcltklib.rb” at ruby’s library directory  
> (.e.g /usr/lib/ruby/1.8).  
> For example,  
> ----- tcltklib.rb -----------------------------------------  
> ver = ENV[‘RUBYTK\_VERSION’]  
> if ver && !ver.empty?  
> require “tcltklib.#{ver}.so”  
> else  
> require “tcltklib.so”  
> end

Hey, that’s a nice trick. Thanks!

> The following depend on an unofficial feature of ruby’s dll loading.  
> At present, it will work. But I don’t recomment it.

BTW, what’s here isn’t an official feature? I do “ri Kernel#require” and  
(I think) it describes everything needed to make this work: Ruby first  
looks for an .rb file (this enables us to inject our loader script), and  
then it’s possible to explicitly load a .so (or .dll). So why isn’t your  
trick future-proof?
