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

Tk using C

4 views
Skip to first unread message

Bart C

unread,
Dec 17, 2004, 10:40:42 AM12/17/04
to
I've seen Tkinter at work in Python.

Can I do something similar in C language?

I want to build dialog windows in C using the tk-like functions I saw in
Python.

Thanks

Bart.


Bart C

unread,
Dec 18, 2004, 11:27:34 AM12/18/04
to
"Bart C" <b...@freeuk.com> wrote in message news:41c2...@212.67.96.135...

> I've seen Tkinter at work in Python.
>
> Can I do something similar in C language?

What I've found so far suggests this is in fact possible but finding things
out is proving nigh impossible.

Most references are geared to using tcl itself or via Python.

I have found (this is for Windows):

* tk/tcl C header files
* tk/tcl DLL files containing lots of interesting functions
* A code fragement in C that creates what looks like a tk window (not
compileable yet)
* LIB files which could be for those dlls

What I'm missing is:

* API docs for the C interface
* Just one simple program to get a window and a button working then I can
work from there. So far stalled by weird compiler errors, from 2 different C
compilers, trying to compile the code fragment. I'm sure that linking will
be fun as well.

Any reassurance that I am on the right lines and that I'm not wasting my
time trying something that is not possible would be appreciated.

Bart.


Dariusz Kuliński / TaKeDa

unread,
Dec 18, 2004, 12:29:57 PM12/18/04
to
On Sat, 18 Dec 2004 16:27:34 -0000, Bart C wrote:

> What I've found so far suggests this is in fact possible but finding things
> out is proving nigh impossible.
>
> Most references are geared to using tcl itself or via Python.
>
> I have found (this is for Windows):
>
> * tk/tcl C header files
> * tk/tcl DLL files containing lots of interesting functions
> * A code fragement in C that creates what looks like a tk window (not
> compileable yet)
> * LIB files which could be for those dlls
>
> What I'm missing is:
>
> * API docs for the C interface
> * Just one simple program to get a window and a button working then I can
> work from there. So far stalled by weird compiler errors, from 2 different C
> compilers, trying to compile the code fragment. I'm sure that linking will
> be fun as well.
>
> Any reassurance that I am on the right lines and that I'm not wasting my
> time trying something that is not possible would be appreciated.
>
> Bart.

I think you should look there:
http://www.tcl.tk/man/

Here is probably what you're looking for:
http://www.tcl.tk/man/tcl8.4/TkLib/contents.htm

--
tak...@IRCnet.EFnet, ICQ# 15827691, TLEN: taked4
*http://eggdrop.takeda.tk - forum dot. botów na bazie eggdropa*
*http://eggwiki.takeda.tk - pomoc w używaniu botów po polsku*

Bart C

unread,
Dec 18, 2004, 2:44:51 PM12/18/04
to

"Dariusz Kulinski / TaKeDa" <5570...@NOsneakemailSPAM.com> wrote in
message news:wu3ybnoi...@stupidworms.takeda.tk...

> On Sat, 18 Dec 2004 16:27:34 -0000, Bart C wrote:

>> What I'm missing is:
>>
>> * API docs for the C interface

> I think you should look there:


> http://www.tcl.tk/man/
>
> Here is probably what you're looking for:
> http://www.tcl.tk/man/tcl8.4/TkLib/contents.htm

OK thanks. I just need now a compiler that will work properly, I've tried 3
or 4 so far, but some more free ones still to go.

Bart.


lcc-win32:
complains about one of the decls in tcldecls.h but is no different from
those before or after

digitalmars C:
compiles headers but needs explicit cast in this line in the test
program:
mainWindow = Tk_CreateMainWindow( interp, display, argv[0] , "Tk")

Pelles C:
Had trouble compiling <windows.h> and loads of errors in tcl headers

gcc/Mingw:
Got nowhere. Didn't even have <stdio.h>

Bart C

unread,
Dec 18, 2004, 6:34:39 PM12/18/04
to

"Bart C" <b...@freeuk.com> wrote in message news:41c4...@212.67.96.135...

....


> OK thanks. I just need now a compiler that will work properly, I've tried
> 3 or 4 so far, but some more free ones still to go.

I've given up on C compilers.

I can use non-conventional methods to access and call the functions in the
TK/TCL84.DLL files.

But it would be useful to know:

* Do the TK/TCL functions use Windows or C calling conventions? Ie. are
the params pushed right to left or left to right, and is stack adjustment
required by the caller?

Thanks.

Bart.

Chris McDonald

unread,
Dec 18, 2004, 8:24:49 PM12/18/04
to
"Bart C" <b...@freeuk.com> writes:

>* Do the TK/TCL functions use Windows or C calling conventions? Ie. are
>the params pushed right to left or left to right, and is stack adjustment
>required by the caller?

Windows is an operating system, C is a programming language.
They may each support their own parameter evaluation ordering -
how would *you* rationalize the evaluation ordering of a C program running
under Windows?

It is far more likely that the operating system and/or the hardware
architecture is the driving force for the employed evaluation order,
particularly if you wish to link/call functions across different languages.
Moreover, C does not define a single parameter evaluation ordering.

The best advice for writing portable programs, is to never be reliant on
the order of parameter evaluation aand passing.

______________________________________________________________________________
Dr Chris McDonald E: ch...@csse.uwa.edu.au
Computer Science & Software Engineering W: http://www.csse.uwa.edu.au/~chris
The University of Western Australia, M002 T: +618 6488 2533
Crawley, Western Australia, 6009 F: +618 6488 1089

Steve Cassidy

unread,
Dec 18, 2004, 9:00:49 PM12/18/04
to
Bart C wrote:

> OK thanks. I just need now a compiler that will work properly, I've tried 3
> or 4 so far, but some more free ones still to go.
>

Umm, so you want to call Tk directly from C but you don't have a working
C compiler...mingw/gcc is the answer to how to build Tcl and Tk on
Windows, there are documents on the wiki (http://mini.net/tcl/)
describing how to go about this.


Tk doesn't have an explicit interface to creating and making use of
widgets from C, it's geared towards making things accessible to Tcl
scripts. That's why the Python interface works by embedding the
tcl interpreter and implementing Tkinter calls as calls to snippets of
tcl code. You could do the same from C via the Tcl_Eval interface. It's
not clear what you'd gain from doing this however.

The Tcl way of doing things is to write C coded extensions for
particular bits of functionality (like signal processing, hardware
interfacing, etc) and then write the interface in Tcl calling out to
your C code when needed. This works really well, as many would testify here.

Steve

Cameron Laird

unread,
Dec 19, 2004, 7:08:10 PM12/19/04
to
In article <41c4e0cc$0$1121$afc3...@news.optusnet.com.au>,

Steve Cassidy <Steve....@mq.edu.au> wrote:
>Bart C wrote:
>
>> OK thanks. I just need now a compiler that will work properly, I've tried 3
>> or 4 so far, but some more free ones still to go.
>>
>
>Umm, so you want to call Tk directly from C but you don't have a working
>C compiler...mingw/gcc is the answer to how to build Tcl and Tk on
>Windows, there are documents on the wiki (http://mini.net/tcl/)
>describing how to go about this.
.
.
.
It *does* seem like a curious situation, doesn't it?

Bart, Mingwin certainly works in this role for quite a
few of us. I wonder, though, if you realize how com-
fortable it can be to work with Tk from Tcl itself. I
understand you began with Tkinter, and have some reason
for looking for an alternative. The Tcl interpreter
can be a great vehicle for accessing Tk *and* C-coded
objects. Does that help?

Bart C

unread,
Dec 19, 2004, 8:04:46 PM12/19/04
to

"Cameron Laird" <cla...@lairds.us> wrote in message
news:hdeh92-...@lairds.us...


> Bart, Mingwin certainly works in this role for quite a
> few of us. I wonder, though, if you realize how com-
> fortable it can be to work with Tk from Tcl itself. I
> understand you began with Tkinter, and have some reason
> for looking for an alternative. The Tcl interpreter
> can be a great vehicle for accessing Tk *and* C-coded
> objects. Does that help?

I've *admired* tkinter in Python (never used it though), and wanted to
import the functionality into my non-C/non-Python application. I also write
compilers/interpreters so for me bypassing the idiosyncrasies of C compilers
is both attractive and viable, if rather more work (rewriting headers for
example).

But you're right, I should learn Tk/Tcl first, I'm not even sure why they
are separate (why not Tkl?). I'm doing that now. And in the long term I
should obtain a proper C compiler, although anything gcc-connected seems
large and daunting (some 200 pages? just of command-line options seemed a
bit OTT).

Bart.


David N. Welton

unread,
Dec 20, 2004, 2:48:35 AM12/20/04
to
"Bart C" <b...@freeuk.com> writes:

> But you're right, I should learn Tk/Tcl first, I'm not even sure why
> they are separate (why not Tkl?). I'm doing that now. And in the
> long term I should obtain a proper C compiler, although anything
> gcc-connected seems large and daunting (some 200 pages? just of
> command-line options seemed a bit OTT).

The reason they are linked together is a clever one linked to the idea
behind Tcl. To wit, that it's much faster and more flexible to write
code in a scripting language than with a compiled language like C.
The logical conclusion for Tk is that it makes sense to do the low
level basics that must be as fast as possible in C, and then build up
from that as scripts. So what you see as 'Tk' actually includes a lot
of Tcl code, and thus requires Tcl itself.

What's ironic about this is that at times it makes people from *other*
scripting language communities turn their noses up. They would prefer
having everythin in lowest-common-denominator-C... An interesting
conundrum.

Ciao,
--
David N. Welton
Personal: http://www.dedasys.com/davidw/
Apache Tcl: http://tcl.apache.org/
Free Software: http://www.dedasys.com/freesoftware/
Linux Incompatibility List: http://www.leenooks.com/

Donal K. Fellows

unread,
Dec 20, 2004, 5:04:08 AM12/20/04
to
Bart C wrote:
> I'm not even sure why they are separate (why not Tkl?).

They are separate because many people want to use just Tcl and not Tk
at all (e.g. in server environments, which is another significant use
for Tcl). Add to that the fact that they started out with Tk being an
extension to Tcl (though from the same author) and you've got why
things are the way they are.

Donal.

David N. Welton

unread,
Dec 20, 2004, 6:58:50 AM12/20/04
to

I guess I should wake up before I post in the morning...

Cameron Laird

unread,
Dec 20, 2004, 7:08:03 AM12/20/04
to
In article <41c6...@212.67.96.135>, Bart C <b...@freeuk.com> wrote:
.
.
.

>import the functionality into my non-C/non-Python application. I also write
>compilers/interpreters so for me bypassing the idiosyncrasies of C compilers
>is both attractive and viable, if rather more work (rewriting headers for
>example).
>
>But you're right, I should learn Tk/Tcl first, I'm not even sure why they
>are separate (why not Tkl?). I'm doing that now. And in the long term I
>should obtain a proper C compiler, although anything gcc-connected seems
>large and daunting (some 200 pages? just of command-line options seemed a
>bit OTT).
>
>Bart.
>
>

I don't understand your relation to C compilers. One
growing capability of Tcl, though, is as a language
for writing compilers <URL: http://wiki.tcl.tk/3687 >.
I repeat: perhaps you'll be able to do *everything*
you want in Tcl alone.

Ralf Fassel

unread,
Dec 22, 2004, 10:33:05 AM12/22/04
to
* "Bart C" <b...@freeuk.com>

| OK thanks. I just need now a compiler that will work properly, I've
| tried 3 or 4 so far, but some more free ones still to go.

M$ gives away the commandline version of the VC++ compiler for free,
see

http://msdn.microsoft.com/visualc/vctoolkit2003/

for the details.

R'

0 new messages