TclTK-Prolog Connection

Introduction

We (some friends && me) are developing prolog applications using SICSTUS-prolog on a Unix machine. Because it doesn't support GUI programming, we use Tcl/Tk for that. Sicstus can actually talk to Tcl using a special library. Wow - our goal was reached - Prolog with a nice and user friendly GUI..
After a while, we wanted to port our applications to the Windows95 platform (The first version in 1996 was for Win3.11 and Win32S - because that old stuff was installed in the pc rooms of the KUL). We use SWI-Prolog in Windows (Main reason: IT IS FOR FREE). But.. shh.. There was no library for interfacing to Tcl/Tk available.. That's why we've developed one on our own. It's right here on this page for download.

Tcl/Tk 8.0.5 Version available 

New version of the Tcl/Tk prolog interface library available.

Download library

If you enter your email, you'll be notified about future major changes.
E-Mail (Optional)
I promise -- no junk mail. The data you supply is private -- only i get to know your email address.

If this form does not work, try: Download

Linx

Feed Back

Pls let me know what you think about this library..

Commands

Prolog side Tcl/Tk side
tcl_new(-Interp)
tcl_delete(+Interp)
tcl_eval(+Interp,+Command,-Result)

tk_new(+Opts,-Interp)
tk_do_one_event
tk_next_event(+Interp,-Event)
tk_main_loop

tcl_eval_file/1
tcl_about/0
tcl_result/0
tcl_string/2
tcl_airity/2
tcl_exit/0

prolog_event EventName(Parameters,...)

Example

I know this is not what you call 'a nice GUI' - but it's only a simple example.. if you want to see the real power than download it and run the 3D puzzle example :o) 
Prolog side Tcl/Tk side
start:-
   tk_new([], I)
   tcl_eval(I, 'source demo.tcl', _),
   tcl_eval(I, 'start', _),
   main_main_loop(I,0),
   tcl_delete(I).

main_main_loop(I,Num) :-
   tk_next_event(I, Event),
   (handle(I,Event) ->
      NewNum is Num + 1,
      tcl_eval(I,[set, loopctr, NewNum],_),
      main_main_loop(I,NewNum)
   ;
      true
   ).

handle(_,exit) :-
   write('Terminating demo !'), 
   nl,
   fail.

handle(_,plwrite(Txt)) :-
   write(Txt),
   nl.

global loopctr sendstr image1a

proc init_vars {} {
   global loopctr sendstr siz
   set loopctr 0
   set sendstr "Nothing"
}

proc init_screen {} {
   wm title . "Tcl/Tk-Prolog demonstration"
   init_vars
   init_buttons
}

proc start {} {
   init_screen
}

proc destroyall {} {
   destroy .butt
   destroy .graf
}

proc make_entry {wnpt txt cnvar wd} {
   frame $wnpt
   label $wnpt.tx -text $txt -anchor w
   entry $wnpt.en -textvariable $cnvar -width $wd
   pack  $wnpt.tx -side left  -anchor w -expand 1 -fill x
   pack  $wnpt.en -side right -anchor e
   pack  $wnpt -side top -expand 1 -fill x
}

proc make_label {wnpt txt1 txt2} {
   frame $wnpt
   label $wnpt.tx -text $txt1
   label $wnpt.en -text $txt2
   pack  $wnpt.tx -side left  -anchor w
   pack  $wnpt.en -side right -anchor e
   pack  $wnpt -side top -expand 1 -fill x
}

proc make_button {wnpt txt act} {
   button $wnpt -text $txt -command $act
   pack $wnpt -side top -expand 1 -fill x
}

proc init_buttons {} {
   frame .butt
   make_entry  .butt.lop "Loop-counter" loopctr 4
   make_entry  .butt.ent "String" sendstr 20 
   make_button .butt.str "Send" "sendstr"
   make_button .butt.ext "Exit" "prolog_event exit"
   pack .butt -side left -anchor nw
}

proc sendstr {} {
   global sendstr
   prolog_event plwrite($sendstr)
}

proc msg_box {msg} {
   toplevel .msg
   message .msg.txt -relief sunken -border 2 -width 10c \
   -text $msg
   button .msg.bt -relief raised -text "OK" -command "destroy .msg"
   pack .msg.txt .msg.bt -side top
}

proc inputbox {title txt default varname proc} {
   global $varname
   toplevel .fdlg
   wm title .fdlg $title
   label .fdlg.txt -text $txt
   pack .fdlg.txt -side top
   entry .fdlg.inp -textvariable $varname
   pack .fdlg.inp -side top -expand 1 -fill x
   frame .fdlg.okcanc
   button .fdlg.okcanc.ok -text "OK" -command "destroy .fdlg; $proc"
   button .fdlg.okcanc.canc -text "Cancel" -command "destroy .fdlg"
   pack .fdlg.okcanc.ok .fdlg.okcanc.canc -side left
   pack .fdlg.okcanc -side bottom
   if {$default!=0} {set $varname $default}
   focus .fdlg.inp
}

Home