TickleSharp

TickleSharp

From the TickleSharp project page, Scott Adams said that: TickSharp is a portable binding to the Tcl/Tk scripting language for the .NET platform. The assembly consists of two files, one is a small C wrapper library that allows for Callbacks into your .NET code, and the other is the assembly itself written in C#. The C# code uses P/Invoke to get at the wrapper and Tcl/Tk DLL's.

TickleSharp 已在 MS.NET, Mono, DotGNU 這些平台通過測試,要開發 TickleSharp App,只要把 TickleSharp.dll, tclwrapper.dll (libtclwrapper.so for Linux) 放在 bin 資料夾即可。另外,你還要裝個 Tcl/Tk 環境才能執行程式,例如 ActiveTcl

底下提供幾個 Embed Tcl/Tk into dotNet Application 的範例 (TickleSharpSamples Download):

HelloTcl

A HelloTcl Program:

using System;
using TickleSharp;

namespace TickleSharpExamples
{    
    public class HelloTcl
    {
        static Tcl tcl;
        
        [STAThread]
        static void Main()
        {
            tcl = new Tcl();
            tcl.Eval("expr 5 * 6");
            
            Console.WriteLine("expr 5 * 6 = " + tcl.Result);
        }
    }
}

HelloTk

A Hello Tk Program (GUI frontend):

using System;
using TickleSharp;

namespace TickleSharpExamples
{
    
    public class HelloTk
    {
        static Tk tk;
        
        [STAThread]
        static void Main()
        {
            // Create a tcl interpreter with Tk initialized
            tk = new Tk();
            
            // Create the GUI
            tk.Eval("wm title . {Hello Tk}");
            tk.Eval("button .b -text {Say Hello} -command {sayHello} -padx 20");
            tk.Eval("pack .b");
            tk.Eval("proc sayHello {} {tk_messageBox -message {Hello Tk} }");
            
            // Enter Tk_MainLoop
            tk.Run();
        }
    }
}
posted @ 2011-05-31 20:49  greencolor  阅读(485)  评论(0编辑  收藏  举报