[Tk] program file name problem

  • Thread starter email55555 email55555
  • Start date
E

email55555 email55555

A sample Tk program likes:

require 'tk'
TkLabel.new:)text=>'Hello').pack
Tk.mainloop

Save it to a file named as "tk" or "tk.rb" do not have any problem to run it.
However, save it to a file like "button.rb" or "scale.rb",
when run it, you will get trouble.

I know that it is not a good idea to save Tk program to button.rb or
scale.rb ... etc. But I would like to understand:

(1) What's going wrong ? File name collision with Tk lib ?
( require 'tk' will load no correct files ?)

(2) So, what are names need to be avoid to use ?
All files name under <ruby_home> / lib / ruby / 1.8 / tk are reserved
file names when using tk library ?
If I am using tkextlib, I must avoid using file names under the
tkextlib folder too ?

Thank you.
 
H

Hidetoshi NAGAI

Hi,

From: email55555 email55555 <[email protected]>
Subject: [Tk] program file name problem
Date: Fri, 24 Dec 2004 03:49:39 +0900
Message-ID: said:
A sample Tk program likes:

require 'tk'
TkLabel.new:)text=>'Hello').pack
Tk.mainloop

Save it to a file named as "tk" or "tk.rb" do not have any problem to run it.
However, save it to a file like "button.rb" or "scale.rb",
when run it, you will get trouble.

I saved your script as "label.rb" and "button.rb".
But, unfortunately, I couldn't re-generate your trouble.
Of course, if the script is saved as "tk/label.rb" on the directory
which has higher priority than the Ruby/Tk system directory,
it will have to generate troubles.
Please check your $LOAD_PATH and $LOADED_FEATURES.
 
E

email55555 email55555

I saved your script as "label.rb" and "button.rb".
But, unfortunately, I couldn't re-generate your trouble.
Of course, if the script is saved as "tk/label.rb" on the directory
which has higher priority than the Ruby/Tk system directory,
it will have to generate troubles.
Please check your $LOAD_PATH and $LOADED_FEATURES.

Save it under any directory (folder) as you like on the name 'button.rb'
Of couse, it has no problem to run it, but try move your mouse cursor
to the generate Tk window.

Then you will get this error message window:
Error: unknown option "-state"
[OK] [Skip Messages] [Details>>]

Click on detail, here is the detail error message:
unknown option "-state"
unknown option "-state"
while executing
"$w cget -state"
(procedure "tk::ButtonEnter" line 3)
invoked from within
"tk::ButtonEnter ."
(command bound to event)

I am using now Tcl/Tk 8.4, and still have this problem.
Again, save to 'button.rb' or 'scale.rb' and no problem to run it,
but move the mouse cursor to the main window (ex. move to the "Hello" label )
then this error dialog message araise...

Thank you.
 
E

email55555 email55555

Retest this problem on Linux platform...
Linux platform does not have this problem.
So, it seems this problem only happen on M$ window platform ( I am
using one-click install binary distribution ).
 
H

Hidetoshi NAGAI

Hi,

From: email55555 email55555 <[email protected]>
Subject: Re: [Tk] program file name problem
Date: Sat, 25 Dec 2004 08:22:45 +0900
Message-ID: said:
So, it seems this problem only happen on M$ window platform ( I am
using one-click install binary distribution ).

I tried. Probably, that is a Tcl/Tk's bug on Windows.
Tcl/Tk has a library named 'button.tcl'.
If you use a same name as a Tcl/Tk library (without the extention)
and Tcl/Tk requires the library on your script, the trouble will happen.

# I created 'button.tcl' which create only one button.
# When do "wish button.tcl", wish shows the error dialog.

Therefore, maybe, there is no way to avoid the problem completely.
On Windows, please don't use a same name for the script called at
first (that is, the script name is set to $0) as one of ** Tcl/Tk's **
library name (e.g. don't use 'button.rb' or 'button', because of
existence of Tcl/Tk library 'button.tcl').

# If the script is only required from the startup script, it has no
# problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top