Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does Tk require Tcl?

101 views
Skip to first unread message

Adam Jensen

unread,
Jul 25, 2018, 9:01:27 PM7/25/18
to
Hello,

I would like to write a very simple "Hello, World" Tk program in C, then
compile and run it. This is a first step towards extending CLIPS[1] with
Tk, in much the same way that Python, Ruby, and Perl have a Tk extension.

[1]: <http://www.clipsrules.net/>

** What would this C program look like and how should it be compiled? **

This little example would answer many questions.


Arjen Markus

unread,
Jul 26, 2018, 5:01:29 AM7/26/18
to
I have never tried that myself, but I would say: yes, Tk does require Tcl. First of all because the widget's bindings to events are implemented via Tcl code. Second, much of the interaction between Tk widgets and the program itself will require types defined by the Tcl library, such as Tcl_Obj.

You may want to get hold of one of the books on Tcl and Tk where these aspects are discussed, one such being discussed on http://wiki.tcl.tk/22519.

Mind you: it is a somewhat underdeveloped topic. You can find bits and pieces on the Wiki, but as far as I know, there are no comprehensive tutorials. Most of the stuff is documentation of the underlying API and then there are complete applications, two of which:
- The wish application that comes with Tcl/Tk is a canonical example.
- PLplot - http://plplot.sf.net - contains a program for running the Tcl/Tk binding of the plotting library that might serve as an example of a C program.

But like I said, these are complete applications, not lean and mean examples for instructing people.

Regards,

Arjen

Ashok

unread,
Jul 26, 2018, 6:48:47 AM7/26/18
to
I am not sure if you are aware of TclCLIPS which is a Tcl binding for
CLIPS. There is also TixCLIPS which is a Tk interface for the same.
Search the Tcler's wiki for both.

However, I suspect the code may or may not be online anymore but if not
perhaps the wayback machine might help.

/Ashok

Christian Gollwitzer

unread,
Jul 26, 2018, 6:59:52 AM7/26/18
to
Hi Adam,

Am 26.07.2018 um 03:01 schrieb Adam Jensen:
> I would like to write a very simple "Hello, World" Tk program in C, then
> compile and run it. This is a first step towards extending CLIPS[1] with
> Tk, in much the same way that Python, Ruby, and Perl have a Tk extension.

As Arjen said, using Tk without Tcl is pretty much impossible. Python's
Tkinter (et al.) works this way, they construct Tcl commands (from
strings) and send them to an embedded Tcl interpreter. In C, you use the
functions Tcl_Eval() and Tcl_EvalObj() to run any arbitrary Tcl code.

What you want to do is called "embedding Tcl" in the Tcl world. Most C
programmers here work the other way round, the write C code which is
then loaded into Tcl ("extending Tcl"). That's why you find only little
tutorials for that. Basically, you need to link against the Tcl library
(NOT stub), call TclFindExecutable(), then Tcl_CreateInterp() and then
you get a Tcl_Interp which you can use to run Tcl commands.

The hard part is to do the callbacks - when the user clicks on a button,
you must make sure that code from your language runs.

And BTW, Python's Tkinter did a few things wrong. grid and pack became
methods of the widget objects, which feels very unnatural. It also does
not allow to use ASCII layout like this in Tcl

grid .a .b
grid .c x

So consider to make grid free functions in your wrapper.

Christian

Adam Jensen

unread,
Jul 27, 2018, 8:12:16 PM7/27/18
to
I found a link to [TclCLIPS](http://fios.com/tcl/TclClips2001.zip) on the
[wiki](http://wiki.tcl.tk/3510). It's not what I had in mind but it is an
interesting reference and its existence (it's a resource) might change my
plans. Thanks for the pointer!

Adam Jensen

unread,
Jul 27, 2018, 8:44:28 PM7/27/18
to
Thanks, Christian. That's very useful information. I might cobble my
project together in a way very different from what I originally had in
mind.

Adam Jensen

unread,
Jul 27, 2018, 9:02:01 PM7/27/18
to
On Thu, 26 Jul 2018 02:01:26 -0700, Arjen Markus wrote:

> You may want to get hold of one of the books on Tcl and Tk where these
> aspects are discussed, one such being discussed on
> http://wiki.tcl.tk/22519.

Thanks, Arjen. Wow, that book is almost $50!

Side note: Printing software documentation on paper seems goofy to me.
It's not like this stuff is Algebra or Physics. It's shorthand for a
collection of little automation knickknacks of process and procedure that
is all together very folksy and parochial. Also, software is soft: it
changes frequently. It seems like the documentation should be carefully
linked and managed along with the software source to keep the information
coherent and correct. What tools like Tcl, Perl, Python, etc. need are
very effective reference, tutorial, and cookbook documentation that is an
integral part of the user's development environment. </rant> ;)

Harald Oehlmann

unread,
Jul 30, 2018, 3:05:40 AM7/30/18
to
Did you look into RubyTk, PerlTk, Python Tk ?
https://tkdocs.com/
AFAIK, all those extensions use a small tcl interpreter as a bridge.

Just an idea,
Harald
0 new messages