LoginSignup
2

More than 5 years have passed since last update.

Tcl / Tk for Dlang : getting started in Windows

Posted at

There is a working Tcl/Tk binding for D, but getting it to work in windows is a little tricky.

If you are familiar with tkinter in Python, tkd is very easy to start with, since while D is under the family of C-style languages, the syntax is very similar to Python (basically imagine python with braces and semicolons).

Make sure DUB is available.

  1. dub init {project-name} tkd
  2. Add the following to your dub.json.
"lflags":["-L/exet:nt/su:windows"],
"postGenerateCommands-windows-x86": [   
    "copy $TCLTK_PACKAGE_DIR\\dist\\x86\\tcl86t.dll build\\tcl86t.dll /y",   
    "copy $TCLTK_PACKAGE_DIR\\dist\\x86\\tk86t.dll build\\tk86t.dll /y",    
    "xcopy $TCLTK_PACKAGE_DIR\\dist\\library build\\library /i /e /y",   
],

Note that I'm using "targetPath":"./build",

The additional linker flags is to prevent the console window from popping up when you start the program.

If done correctly you should have the following folder structure.

build
├── app.exe
├── tcl86t.dll
├── tk86t.dll
└── library
    └── *.tcl files

A sample program can be found below.


import tkd.tkdapplication;                               // Import Tkd.

class Application : TkdApplication                       // Extend TkdApplication.
{
    private void exitCommand(CommandArgs args)           // Create a callback.
    {
        this.exit();                                     // Exit the application.
    }

    override protected void initInterface()              // Initialise user interface.
    {
        auto frame = new Frame(2, ReliefStyle.groove)    // Create a frame.
            .pack(10);                                   // Place the frame.

        auto label = new Label(frame, "Hello World!")    // Create a label.
            .pack(10);                                   // Place the label.

        auto exitButton = new Button(frame, "Exit")      // Create a button.
            .setCommand(&this.exitCommand)               // Use the callback.
            .pack(10);                                   // Place the button.
    }
}

void main(string[] args)
{
    auto app = new Application();                        // Create the application.
    app.run();                                           // Run the application.
}

You should see this:

without the console window.

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2