Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Calling a telnet application at the button click

Posted by skumar003 (skumar003), 28 January 2003
I have an application that connects to a host. That needs to be executed at the command line.

execute port@host this.package.

How do I call this in a GUI button so that I click the button I get that executed.


Posted by admin (Graham Ellis), 28 January 2003
Then you'll be wanting the Tk extension and the expect extension - you'll find them together in "expectk".

Wrap the spawn send and expect sequence (and everything
else you want to do to run the the remote command) into a
proc, and create a widget (probably a button) that calls it up with its -command option.

Use a pack geometry manager to display the button, and when your code reaches the end it will wait for button hits.   You'll probably also want to create and pack a label onto which to display your results, and you might want to have a look at updateidlestasks if your remote application can take a while to run - otherwise your user may be left thinking that the application has hung.

It's fabulous fun writing this sort of thing, code typically turns out quite short, but you really need a good head on your shoulders and to understand things like deferred blocks ....

Posted by skumar003 (skumar003), 28 January 2003
Have U seen a free source example of this kind anywhere on the net?

Posted by admin (Graham Ellis), 28 January 2003
Well - it's really just a question of combining Tk techniques and Expect techniques ... can't say that I've seen an example posted for free on the net that fulfills the criteria;  the nearest I can offer is an application that spawns a ping and reports back - on our web site at
and (you're in luck!) it's the course example "tkpingle" that's mentioned on the "view sample program" box.

Posted by skumar003 (skumar003), 28 January 2003
Can I   invoke a  batch file by the click of a button?

connect port@host scriptfile

---What I want to achieve--------------

button .redo -text "Connect to NE" -command {
connect port@host scriptfile


Posted by admin (Graham Ellis), 29 January 2003
If the batch (script) file is located (and to run) on the computer that's running the Tcl/Tk script then, yes ... have a look at the exec command, and also the catch command so that any errors it generates won't cause the whole Tcl program to fail.

If the batch command script requires interaction, or to be run on a remote machine (as your initial question kinda implies) then expectk is the thing to use.  There's thorough coverage in Don
Libe's book "Exploring Expect" - full book details at

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho