This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Beginner Help for using TK

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
l
logitech
Voice
Posts: 3
Joined: Wed Apr 30, 2008 6:06 am

Beginner Help for using TK

Post by logitech »

I am a beginner to TCL programming and I'm facing a problem with using the "wish" command from within a file, though the same command works perfectly in the tclsh prompt.


The following commands in the TCL command prompt ( invoked with the tclsh command) work and a new frame is created.
---
% wish
% frame .mv_ex
wm title . "Title"
pack .mv_ex
--

When written in a file "trial.tcl", the wish command doesn't seem to work and returns an error.

Contents of the file "trial.tcl"
--
#!/usr/bin/wish -f
frame .mv_ex
wm title . "Animation in canvas"
pack .mv_ex
---
Error returned when "trial.tcl" is executed.
--
tclsh trial.tcl
invalid command name "frame"
while executing
"frame .mv_ex"
(file "trial.tcl" line 3)
---

Please help!! Thanks in advance. :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

wish is a tcl/tk shell, whereas tclsh is a tcl shell... the difference is the Tk-extensions, which is basically a graphical interface API.

Much simplified, Tk-commands won't work in tclsh...

Edit:
Might add, wish is not a tcl command, but a separate interpreter. When you type "wish" in tclsh, tcl simply forks a child and executes the external application wish within here. Hence, any further text written on stdin is directed to wish, rather than tclsh. When scripting however, the whole script is executed in tclsh...

Solution: if you wish to develop Tk-tclets, use wish, not tclsh..
NML_375
l
logitech
Voice
Posts: 3
Joined: Wed Apr 30, 2008 6:06 am

@nml375

Post by logitech »

Thanks!

But do you know how to use wish from within a file, so that the file containing Tk -commands executes on a tclsh shell?[/quote]
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Yes, use wish, not tclsh.

wish can take a script-file as argument just like tclsh does...
You'll have to accept that whenever you're using tclsh, you can't have any fancy GUI or other graphics - just print text on stdout. If you want X11/Xwin/etc graphics, use the wish interpreter...
NML_375
l
logitech
Voice
Posts: 3
Joined: Wed Apr 30, 2008 6:06 am

re

Post by logitech »

oh fine... got it now... thanks a lot,,, :-)
Post Reply