Updated 2013-01-18 03:04:59 by pooryorick

With a compiler, and a modified tclAppInit, it is of course pretty easy to make a executable to run a particular set of tcl/tk code. However, it is nice to be able to write pure tcl/tk as much as possible to accomplish the same task. There are a few aspects to this:

  • provide an icon for the application which can be double-clicked on to run
  • allow drag-n-drop of documents onto the icon to interact with them
  • allow other applications to send files to the application.
  • ...

Obviously there may be some platform-specific aspects to correct "native" behaviour as well (for example on Windows, we might want to add a shortcut to the application and its help/readme to the Start->Programs menu).

Windows edit

Windows can be configured so that any .tcl file can be double-clicked to launch wish (or tclkit) by default. We can also easily add the application to the Programs menu as follows:
windows::CreateGroup Alphatk ~/Apps/Alphatk8.1 alphatk.tcl AlphaCore/alpha.icr

package require dde
proc windows::CreateGroup {name root script icon} {
    # This won't work with a scripted document.  In that case
    # we will have to be a bit cleverer...
    windows::ProgmanExecute CreateGroup $name
    windows::ProgmanExecute AddItem [file join $root $script] \
         $name $iconfile
    windows::ProgmanExecute AddItem [file join $root Readme.txt] \

proc windows::ProgmanExecute {name args} {
    eval [list windows::DdeExecute PROGMAN PROGMAN $name] $args

proc windows::DdeExecute {service topic name args} {
    set cmd "\[$name\("
    set subcmds [list]
    foreach a $args {
        lappend subcmds "\"$a\""
    append cmd [join $subcmds ","] "\)\]"
    dde execute $service $topic $cmd

But how can we allow 'drag-n-drop' onto an icon for our application? VK 'drag-n-drop' onto an icon will start up application, associated with an icon, with dragged item(s) as parameters, so this is very simple to process.

See ddeexec for a way to associate your applications files with your application such that double-clicking on the application file (eg: data.myapp) opens the data in a running instance of your app. [PT]

Internal Scrollbars

Unix edit

please fill in

MacOS edit

Tcl/tk for MacOS (9 and earlier) comes with a program called Drag & Drop Tclets, which can create Wish shells customised by having a particular Tcl script as startup script. To create such a "Tclet", drag the script onto the Drag & Drop Tclets program.

What Drag & Drop Tclets does is copies an existing Wish shell program (it cannot copy a program that is already running due to file access restrictions, so in particular it cannot copy itself) and then replaces the startup script (which is stored in a resource) in the copy with the script that was dragged onto it.

All other fiddling with Finder appearance of the program and its files is done as with any other MacOS program, i.e., using ResEdit. (Finding that on Apple's website is, as usual, difficult or impossible. Google suggests (2004-06-25) [1] instead when searching for "ResEdit Download".)

See also below on MacOS X.

MacOS X edit

The WishShell application on MacOS X is actually a 'bundle' -- it's a directory of stuff pretending to be an application. If you go inside that directory (which you can do from the command-line shell or by control clicking on the application in the finder), you will find the directory Scripts under Contents/Resources. If there isn't a Scripts directory there then create one. Rename your script to "AppMain.tcl" and place it inside the Scripts directory. "AppMain.tcl" will be sourced when you open (run) the application from the finder -- you now have a new application. You can also replace the application icon (there is a Wish.icns in the bundle).

See also: http://www.codebykevin.com/opensource/tutorial.html for a complete explanation.

If you write a proc "proc tk::mac::OpenDocument {args} {...}", it will be called with the list of file names any time files are dropped onto the Wish application, or "open document" (odoc) events are sent. (This was true also in MacOS 9 and earlier.)

[Wasn't someone intending to write up a bunch of options to mollify Tk's appearance? I remember things like fiddling with borderwidths on Windows, and so on ...]

See gtklook.tcl, ActiveState Style for Tk and also there is a module in tklib [2] that tries to bring some of this together. PT

Also see Ttk, the Tk 8.5 set of widgets to make some widgets look more native.