Hello World program for tcl using xlib

111 views
Skip to first unread message

Hrishikesh

unread,
Dec 30, 2008, 7:06:31 PM12/30/08
to
Hi,

I just started learning tcl and xlib,

I got Hello World program working for tcl as well as xlib seperatly

**tcl**
http://wiki.tcl.tk/300
#! /usr/bin/tcl
puts "hello, world"

**xlib and c**
http://en.literateprograms.org/Hello_World_(C,_Xlib)

But I want to use xlib in tcl, I searched on internet but I couldn't
find Hello World program for tcl and xlib. Any help is appreciated.

If anyone knows some articles, tutorials, websites or books regarding
tcl and xlib please let me know.

Thanks.

Hrishikesh

Donal K. Fellows

unread,
Dec 30, 2008, 8:46:07 PM12/30/08
to
Hrishikesh wrote:
> But I want to use xlib in tcl, I searched on internet but I couldn't
> find Hello World program for tcl and xlib. Any help is appreciated.

The easiest way is to use the Tk toolkit to help. (Add a suitable #!
line if you want.)

package require Tk
button .b -text "Hello world!" -command {exit}
pack .b

That will use xlib on platforms where it is appropriate to do so.

Of course, that code's rather more complex than the classic Tcl "hello
world" example. But then again, GUI's *are* more complex than simple
non-interactive scripts. Can't make it shorter without making it even
more confusing...

Donal (to understand the code, take that code and try changing bits of
it.)

sleb...@gmail.com

unread,
Dec 30, 2008, 8:48:45 PM12/30/08
to
On Dec 31, 8:06 am, Hrishikesh <hrishi....@gmail.com> wrote:
> Hi,
>
> I just started learning tcl and xlib,
>
> I got Hello World program working for tcl as well as xlib seperatly
>
> **tcl**http://wiki.tcl.tk/300

> #! /usr/bin/tcl
> puts "hello, world"
>

Are you sure that works? Shouldn't that be /usr/bin/tclsh?

> **xlib and c**http://en.literateprograms.org/Hello_World_(C,_Xlib)


>
> But I want to use xlib in tcl, I searched on internet but I couldn't
> find Hello World program for tcl and xlib. Any help is appreciated.
>
> If anyone knows some articles, tutorials, websites or books regarding
> tcl and xlib please let me know.
>

Why exactly would you want to use xlib? Tcl comes with the Tk library
which is a nice high level wrapper around several windowing APIs, xlib
included. So:

#! /usr/bin/env wish
pack [label .l -text "Hello World"]

Hrishikesh

unread,
Dec 31, 2008, 1:40:20 PM12/31/08
to
Hi,

First of all thanks for your suggestions.

>The easiest way is to use the Tk toolkit to help. (Add a suitable #!
>line if you want.)

> Why exactly would you want to use xlib? Tcl comes with the Tk library


> which is a nice high level wrapper around several windowing APIs, xlib
> included. So:
>
> #! /usr/bin/env wish
> pack [label .l -text "Hello World"]

The thing is, eventually I want to generate mouse click events at
particular x y co-ordinates using tcl, that's why I want to use xlib
library, and I don't know how to use xlib in tcl thats why I just want
to create hello world program for tcl using xlib so once I know how to
include xlib and use it in tcl I can use other functions.

> Are you sure that works? Shouldn't that be /usr/bin/tclsh?

I am using very old version of red hat (Red Hat 7.3) for this project,
it has tcl 8.3.3, so it works with #! /usr/bin/tcl

Regards,

Hrishikesh

sleb...@gmail.com

unread,
Dec 31, 2008, 6:01:28 PM12/31/08
to
On Jan 1, 2:40 am, Hrishikesh <hrishi....@gmail.com> wrote:
> Hi,
>
> First of all thanks for your suggestions.
>
> >The easiest way is to use the Tk toolkit to help. (Add a suitable #!
> >line if you want.)
> > Why exactly would you want to use xlib?
>
> The thing is, eventually I want to generate mouse click events at
> particular x y co-ordinates using tcl
> <snip>

In that case, have a look at swig (www.swig.org) to generate wrappers
around the required xlib functions.

> > Are you sure that works? Shouldn't that be /usr/bin/tclsh?
>
> I am using very old version of red hat (Red Hat 7.3) for this project,
> it has tcl 8.3.3, so it works with #! /usr/bin/tcl
>

Hmm.. that's strange. Traditionally the tcl interpreter executable is
called tclsh. I guess the RedHat package maintainer thought that was
not intuitive (and created an alias to tclsh?).

Glenn Jackman

unread,
Jan 1, 2009, 8:22:06 AM1/1/09
to

If I recall, the TclX interpreter is called "tcl"

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous

Cameron Laird

unread,
Jan 1, 2009, 8:12:35 AM1/1/09
to
In article <45cb883e-7453-41ed...@u18g2000pro.googlegroups.com>,
Hrishikesh <hrish...@gmail.com> wrote:
.
.
.

>The thing is, eventually I want to generate mouse click events at
>particular x y co-ordinates using tcl, that's why I want to use xlib
>library, and I don't know how to use xlib in tcl thats why I just want
>to create hello world program for tcl using xlib so once I know how to
>include xlib and use it in tcl I can use other functions.
.
.
.
While the Tcl-xlib binding at which you're aiming intrigues
me, Tk has the ability "to generate mouse click events ..."
for some meanings of "mouse click events" <URL:
http://wiki.tcl.tk/10002 >.

Gerald W. Lester

unread,
Jan 1, 2009, 12:21:21 PM1/1/09
to
Hrishikesh wrote:
> Hi,
>
> First of all thanks for your suggestions.
>
>> The easiest way is to use the Tk toolkit to help. (Add a suitable #!
>> line if you want.)
>
>> Why exactly would you want to use xlib? Tcl comes with the Tk library
>> which is a nice high level wrapper around several windowing APIs, xlib
>> included. So:
>>
>> #! /usr/bin/env wish
>> pack [label .l -text "Hello World"]
>
> The thing is, eventually I want to generate mouse click events at
> particular x y co-ordinates using tcl, that's why I want to use xlib
> library, and I don't know how to use xlib in tcl thats why I just want
> to create hello world program for tcl using xlib so once I know how to
> include xlib and use it in tcl I can use other functions.

Do you want to generate the clicks for your application or another application?

Either way, you do not need xlib -- but the answer to the question effects
what is the easiest way to do it.

>> Are you sure that works? Shouldn't that be /usr/bin/tclsh?
>
> I am using very old version of red hat (Red Hat 7.3) for this project,
> it has tcl 8.3.3, so it works with #! /usr/bin/tcl

I'd strongly suggest upgrading the version of Tcl to 8.5.x.

--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

Hrishikesh

unread,
Jan 5, 2009, 8:36:53 PM1/5/09
to
Hi,

Again thanks all of you for your help and comments.

Let me tell you whats my final objective, I would like to create
Automated GUI Testing program in tcl/tk/expect using which I could
able to test my another GUI applications in linux platform. Where I
can record users mouse movements and clicks and then I can generate
those movements and clicks again to automatically to test my other
similar programs.

For that I saw couple of helpful tools

1) Android (http://wiki.tcl.tk/1691)
2) Dogtail (http://people.redhat.com/zcerza/dogtail/) (In python, buts
thats also fine)
3) Linux Desktop Testing Project (http://ldtp.freedesktop.org/wiki/)
4) xautomation (http://www.hoopajoo.net/projects/xautomation.html)
5) TkReplay (http://wiki.tcl.tk/209)
6) TkXext (http://wiki.tcl.tk/2116)

But I couldn't able to get any of them working, I couldn't get, some
of them (Android), whereas I couldn't able to install some (TkXext,
etc) of them.

As there shouldn't be any problem of tcl version I am using so I
placed my target platform as Ubtunu 8.10 with tcl 8.5.

So please help me in this.

Regards,
Hrishikesh

Gerald W. Lester

unread,
Jan 6, 2009, 2:19:41 AM1/6/09
to

First off, do you have the X11 XTEST extension (an X11 not Tcl extension)
installed?

That is required for most of the above to install/work.

Assuming the answer to the above is yes, then posting the *exact* error you
are getting attempting to install/run TkXext etc would allow us to help you
a bit more.

Hopefully someone here has a copuy of Android laying around that they can
upload to an FTP/HTTP site -- it was a very nice porgram/product.

Hrishikesh

unread,
Jan 6, 2009, 3:43:05 PM1/6/09
to
Hi,

I got the TkXext Installer from
http://www.xmission.com/~georgeps/implementation/software/TkXext/TkXext-3.6.12.tar.bz2.

I am using Ubuntu 8.10 (Gnome), As missing file name is '/gps/
runtime8.4/lib/libtclstub84.a' in the following error message, I
thought this package will work only on tcl and tk 8.4 so I installed
tcl and tk 8.4.

As mentioned in the README file from the tarfile I executed 'tclsh
build.tcl' command for building

I debugged some of the error messages in the build process by
installing
1) build-essential
2) libxmu-dev
3) libxtxt-dev (includes X11 XTEST extension)
packages from Synaptic Package Manager. I was also getting error
missing tcl.h and tk.h, as I understand it was looking for these files
in /usr/include but they were in /usr/include/tcl8.4 so I copied all
files in /usr/include/tcl8.4 to /usr/include.

But I couldn't debug following error message. I searched for related
filename on my computer, I found /usr/lib/libtclstub8.4.a file, I
created symbolic link /usr/lib/libtclstub84.a for /usr/lib/
libtclstub8.4.a. But it didn't worked.

Please tell me what I am doing wrong. And also if anybody has copy of
Android please give it to me.

Thanks Gerald,

Regards,
Hrishikesh


ERROR Message:

------------------------------------------------------------------------------------
~/TkXext-3.6.12$ tclsh build.tcl

BUILDING:delete.or.kill.o
gcc -pipe -ggdb -Wall -Wsign-compare -Wstrict-aliasing -O -fPIC -DPIC -
DUSE_TCL_STUBS -DUSE_TK_STUBS -DEXT_VERSION="3.6.11" -I/gps/runtime8.4/
include -I/usr/X11R6/include src/delete.or.kill.c -c
BUILDING:error.o
gcc -pipe -ggdb -Wall -Wsign-compare -Wstrict-aliasing -O -fPIC -DPIC -
DUSE_TCL_STUBS -DUSE_TK_STUBS -DEXT_VERSION="3.6.11" -I/gps/runtime8.4/
include -I/usr/X11R6/include src/error.c -c
.
.
.
.
.
BUILDING:send.string.o
gcc -pipe -ggdb -Wall -Wsign-compare -Wstrict-aliasing -O -fPIC -DPIC -
DUSE_TCL_STUBS -DUSE_TK_STUBS -DEXT_VERSION="3.6.11" -I/gps/runtime8.4/
include -I/usr/X11R6/include src/send.string.c -c
BUILDING:string.to.window.o
gcc -pipe -ggdb -Wall -Wsign-compare -Wstrict-aliasing -O -fPIC -DPIC -
DUSE_TCL_STUBS -DUSE_TK_STUBS -DEXT_VERSION="3.6.11" -I/gps/runtime8.4/
include -I/usr/X11R6/include src/string.to.window.c -c
BUILDING:TkXext.so
ld -Bshareable -x -rpath /gps/runtime8.4/lib:/usr/X11R6/lib
delete.or.kill.o error.o find.o focus.o init.o map.o misc.o move.o
pointer.o reparent.o resize.o send.button.press.o
send.button.release.o send.key.press.o send.key.release.o
send.string.o string.to.window.o -o TkXext.so /gps/runtime8.4/lib/
libtclstub84.a /gps/runtime8.4/lib/libtkstub84.a -lm -L/usr/X11R6/lib -
lX11 -lXmu -lXtst

ERROR:ld: /gps/runtime8.4/lib/libtclstub84.a: No such file: No such
file or directory
--------------------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages