The reason for using tclsh is that the routines are mostly background
batch commands which do not require GUIs. Only in rare special cases
error messages will be necessary to give explicable error messages to
minimize the effort for finding the error.
1. Can anyone explain me what the necessary prerequisites are, that Tk
can be activated by tclsh using package require?
2. Is there any solution for wish without calling [wm withdraw] to avoid
the main window to be displayed?
3. Do I always need an "exit function" to terminate the wish application
explicitely - for tclsh this is not necessary?
THX in advance.
--
Gerhard Reithofer
Tech-EDV Support Forum - http://support.tech-edv.co.at
> 2. Is there any solution for wish without calling [wm withdraw] to avoid
> the main window to be displayed?
afaik there is no way to start wish without a first toplevel.
(a working) package require Tk will fail if the first toplevel
cannot be posted.
>
> 3. Do I always need an "exit function" to terminate the wish application
> explicitely - for tclsh this is not necessary?
in the basic tcl shell the shell will
exit after the last line of (toplevel) code has been executed.
an eventloop can be started with [vwait forever] _BUT_ not with [ gets .. ]
( you need this forex to have fileevents work. )
Tk implicitly starts the eventloop on its own.
The shell will implicitly exit after all eventsources have gone.
( Try [ destroy . ] in a wish. )
uwe
On Sun, 21 Sep 2008, Uwe Klein wrote:
> Gerhard Reithofer wrote:
> > Hi *,
> > I've found an installation of tcl 8.4.2 which gives me the well known
> > can't find package Tk
> > error when calling "package require Tk". Any script can be run by calling
> > "wish", i. e. Tk is installed in general, but it cannot be launched by the
> > require command.
> This wiki page may give some insight ( and help?)
> http://wiki.tcl.tk/2437
I've already found this, but there is no description WHY "package
require Tk" fails - what in detail is missing?
If I understand correct a libtk8.3.so should be present but there is no
such lib on my machine, but a libtk8.3.a is available (its AIX 5.3).
...
> Tk implicitly starts the eventloop on its own.
> The shell will implicitly exit after all eventsources have gone.
> ( Try [ destroy . ] in a wish. )
Ok, that's a good idea.
Unhandy but working solution - if package require Tk works:
------------------------------------------------------
#!/bin/sh
#
# lets start tcl shell\
exec tclsh $0 "$@"
proc app_error {fatal msg} {
package require Tk ; wm withdraw .
append msg "\nPlease call your hotline 01243/567891."
if {$fatal} {
tk_messageBox -type ok -message "Fatal error: $msg" ; exit 1
} else {
tk_messageBox -type ok -message "Warning: $msg" ; destroy .
}
}
######################################
set important_prog IMP_PROG
######################################
if {[auto_execok $important_prog] eq ""} {
app_error 1 "Application '$important_prog' not installed!"
}
if {![info exists env(SHOULD_BE_SET)]} {
app_error 0 "'$important_prog' not configured correctly!"
}
set env(IMPORTANT_VAR) "important environment value"
### etc. etc. etc.
exec $inst_ok
------------------------------------------------------
Should also work on Windows when called via TCLSH.
Any suggestions or better solutions?
THX
A compatible release of Tk must be properly installed in a location
where the Tcl interpreter that is evaluating the script is configured
to search for packages.
Unfortunately folks have demonstrated unlimited creativity in
constructing ways for this to fail. About the only way to get
to the bottom of it is with interactive Q&A. If you can get into
the Tcl'ers chat room sometime when I'm there, I can try to help.
> 3. Do I always need an "exit function" to terminate the wish application
> explicitely - for tclsh this is not necessary?
The wish program keeps its event loop active until all Tk windows
are destroyed.
DGP
That page is mostly about working around bugs in ancient
releases of Tcl/Tk. Mostly useless these days to all
but historians.
>> 3. Do I always need an "exit function" to terminate the wish
>> application explicitely - for tclsh this is not necessary?
> Tk implicitly starts the eventloop on its own.
Just to get extremely nitpicky, Tk makes a request that
an event loop get started for it. If the running program
is tclsh, or any other program built around the Tcl_Main()
routine, the request will be honored. In other embedding
situations, you'll need to check the docs and/or test.
> The shell will implicitly exit after all eventsources have gone.
> ( Try [ destroy . ] in a wish. )
Continuing in nitpick mode, Tk counts windows, not event
sources. An active [after] won't prevent Tk's event
loop from terminating when the last window is destroyed.
Also, when tclsh starts Tk's event loop, that will be the
outer loop. If a [vwait forever] is in a script, that will
start an inner loop nested inside the outer one. This means
the destruction of the last window won't be detected until
after the variable ::forever is set.
DGP
set pname app_error
set pargs { fatal msg }
if {[catch {package require Tk} cerr]} {
set pbody {
if {$fatal} {
puts stderr " $argv0 : Fatal Error : "
} else {
puts stderr " $argv0 : Warning : "
}
puts stderr [ string map {\n \n\i\i} $msg ]
puts stderr "\i\i\iPlease call your hotline 01243/567891."
puts stderr "\aHit \"Any\" key to continue"
if {$fatal} {
exit 1
} else {
puts stderr "Hit \"Any\" key to continue"
gets stdin
}
}
} else {
withdraw .
set pbody {
append msg "\nPlease call your hotline 01243/567891."
if {$fatal} {
tk_messageBox -type ok -message "Fatal error: $msg" ; exit 1
} else {
tk_messageBox -type ok -message "Warning: $msg"
}
}
}
proc $pname $pargs $pbody
should your app really die on a Warning?
uwe
>Hi *,
>I've found an installation of tcl 8.4.2 which gives me the well known
> can't find package Tk
>error when calling "package require Tk".
>Any script can be run by calling "wish", i. e. Tk is installed in
>general, but it cannot be launched by the require command.
Hi Gerhard,
just a wild shot into the dark: IIRC in the dark ages there was a time
when Tk could not be loaded via [package require] (not being a proper
package).
Maybe 8.4.2 stems from this period?
Best regards
Helmut Giese
I'm afraid, that this is THE reason.
The absense of the a shared lib makes me think that way. As I can
remember it was a widley used method to link everything statically in
old AIX versions (I ported postgres ca. 1995 to AIX).
The positive aspect was, that the software could be run for many, many
years over different OS versions and even on different hardware
platforms.
But the bad thing is, that these exe's can't be used dynamically.
THX
> I usually do that a bit different:
>
> set pname app_error
> set pargs { fatal msg }
... much nice stuff deleted ...
> should your app really die on a Warning?
If the app is not installed - definitely Yes ;-)
... but it was just a simplified example.
In reality a more complex error management will be implemented. My main
problem is that I don't want a GUI - just the TCL shell - but in some
situations GUI reactions are intended.
On Sun, 21 Sep 2008, Don Porter wrote:
> Gerhard Reithofer wrote:
> > 1. Can anyone explain me what the necessary prerequisites are, that Tk can
> > be activated by tclsh using package require?
>
> A compatible release of Tk must be properly installed in a location
> where the Tcl interpreter that is evaluating the script is configured
> to search for packages.
what makes Tk "compatible"?
As I can start every package by extending the TCLLIBPATH (or maybe
TCL_LIBRARY) with the corresponding paths, I cannot understand why I
can't "load" Tk.
Q: Where is the "package provide Tk" statement defined?
> Unfortunately folks have demonstrated unlimited creativity in
> constructing ways for this to fail. About the only way to get
> to the bottom of it is with interactive Q&A. If you can get into
> the Tcl'ers chat room sometime when I'm there, I can try to help.
What is "the Tcl'ers chat room"?
I downloaded and tried to start tkchat-linux-ix86, and got:
---------------------------------------------------------------
couldn't load file "/tmp/tcl9Ga5sP": /usr/lib32/libXft.so.2: undefined
symbol: F T_GlyphSlot_Embolden
while executing
"load /home/gerhardr/tkchat-linux-ix86/lib/tk8.5/../libtk8.5.so Tk"
("package ifneeded Tk 8.5.4" script)
invoked from within
"package require Tk 8.4 "
(file "/home/gerhardr/tkchat-linux-ix86/bin/tkchat.tcl" line 36)
invoked from within
"source [file join $starkit::topdir bin tkchat.tcl]"
(file "/home/gerhardr/tkchat-linux-ix86/main.tcl" line 28)
----------------------------------------------------------------
But before wasting too much time, a question:
Could the absence of a dynlib (e.g. libtk8.4.so) explain why in cannot
be loaded as package?
On the other way, this may be a good reason to upgrade to tcl 8.5, I'm
very pleased with the new look and feel ;-)
THX
>> A compatible release of Tk must be properly installed...
> what makes Tk "compatible"?
Matching version number with the Tcl you are attempting the
[package require Tk] in, up to the minor release number.
Tk 8.4.12 is compatible with Tcl 8.4.5. Tk 8.2.3 is not.
> Could the absence of a dynlib (e.g. libtk8.4.so) explain why in cannot
> be loaded as package?
I suppose. But that just illustrates the "properly installed"
part of my statement above.
If a more interactive session getting to the bottom of this
is not feasible, I'd suggest you just get the ActiveTcl
distribution. Probably should just suggest that anyway.
DGP
Ok, finally saw the branch of the discussion that reveals
this is a --disable-shared install on AIX. Mystery solved.
Note that in this circumstance, the error message is correct
(though admittedly lacking in helpfulness). A
[package require]able Tk can't be found, because none has
been installed.
DGP
>
> > If a more interactive session getting to the bottom of this
> > is not feasible, I'd suggest you just get the ActiveTcl
> > distribution. Probably should just suggest that anyway.
>
> Ok, finally saw the branch of the discussion that reveals
> this is a --disable-shared install on AIX. Mystery solved.
yes, "mystery" is solved.
> Note that in this circumstance, the error message is correct
> (though admittedly lacking in helpfulness). A
> [package require]able Tk can't be found, because none has
> been installed.
Thus my "suspicion" was correct, that there must be a dynamic lib, I
suppose that [load] is used to aktivate Tk.
I'm checking now 8.5 - the Activestate Distro has shared libs, as far as
I've seen - but I could not test it until now.
Thanks to all for your help - c.t.l is really a great community :)