Develop Cross-Platform CLI and GUI Tools With Tcl/Tk

Develop Cross-Platform CLI and GUI Tools With Tcl/Tk

使用 Tcl/Tk 开发跨平台 CLI 和 GUI 工具

What if I told you there exists a language, or a whole toolkit that: Can be used to create cross-platform Console and GUI tools or apps; Those GUI apps look native on Windows, Linux and MacOS; Supports safe and efficient threading, non-blocking events and I/O; Has a small footprint of about 100MB with most common packages installed; Can produce very compact single-file apps for any supported platform; Is capable of building robust cross-platform Web Apps; Has existed and been in use by some of the largest corporations for over three decades; Is free and BSD-licensed, so you can do whatever you want with it, or to it. Would you believe me?

如果我告诉你,存在这样一种语言或一套完整的工具包,它具备以下特性:可用于创建跨平台的控制台和 GUI 工具或应用;这些 GUI 应用在 Windows、Linux 和 MacOS 上看起来都像原生应用;支持安全高效的线程、非阻塞事件和 I/O;安装了最常用的包后,占用空间仅约 100MB;可以为任何支持的平台生成非常紧凑的单文件应用;能够构建强大的跨平台 Web 应用;已经存在并被一些大型企业使用了三十多年;它是免费且基于 BSD 许可的,所以你可以随心所欲地使用或修改它。你会相信我吗?

Foreword

前言

Documenting personal experiences on fascinating or useful topics is what I do. Real-time visualization, 3D simulation, data safety, energy efficiency, or even input devices, microcontrollers, and fitness — an endless stream of ideas for new studies and exploration is always on the ToDo list. This particular topic turned up to be quite a bit more involved than I originally planned. But I promise: all information here is what I myself would’ve loved to have known before I started my Tcl/Tk toolkit learning journey.

记录关于迷人或实用主题的个人经验是我的工作。实时可视化、3D 模拟、数据安全、能源效率,甚至是输入设备、微控制器和健身——源源不断的学习和探索想法总是在我的待办事项列表中。这个特定的话题比我最初计划的要复杂得多。但我保证:这里所有的信息都是我在开始 Tcl/Tk 工具包学习之旅前,自己非常希望了解的内容。

I’m writing this long after my honeymoon phase with Tcl/Tk ended, and will try to be as objective and honest as possible. Both to you, and to myself. I have nothing to “sell” except my personal experience, hoping to better inform you and simplify the “onboarding” process if you ever decide to give Tcl/Tk a try. Due to its command-centric nature, Tcl is a powerful, yet widely misunderstood language. I want to contribute to the conversation, aiming to clear up this persistent confusion with concise explanations and concrete examples. And a bit of flair, of course, to keep you entertained.

我在 Tcl/Tk 的“蜜月期”结束后很久才写下这些,我会尽量保持客观和诚实。无论是对你还是对我自己。除了个人经验,我没有什么要“推销”的,只是希望如果你决定尝试 Tcl/Tk,能为你提供更好的信息并简化“入门”过程。由于其以命令为中心的特性,Tcl 是一门强大但被广泛误解的语言。我想为这场讨论做出贡献,旨在通过简洁的解释和具体的例子来消除这种持续存在的困惑。当然,还要加一点点趣味,让你读起来不那么枯燥。

Please note: We’re skipping the “Programming 101” talk here with the assumption that you already have a baseline familiarity with general programming logic. If you know your way around an if statement and know what function is, you’re probably ready to dive straight into Tcl-specific structures and syntax. Think of this article as both a “Tcl hands-up and a primer”, in hopes to make you, too, discover and appreciate this almost 40-year old technology that quietly powers the world. And maybe convince you to try it for yourself, and spread the word. As for the “About the Author” — if you’re interested, please visit the “About” page. Ready? Let’s go.

请注意:我们在这里跳过了“编程 101”的基础讲解,假设你已经对通用编程逻辑有基本的熟悉。如果你知道如何使用 if 语句并了解什么是函数,那么你可能已经准备好直接深入了解 Tcl 特有的结构和语法了。将这篇文章视为“Tcl 的举手礼和入门指南”,希望你也能发现并欣赏这项已经存在近 40 年、默默支撑着世界的科技。也许还能说服你亲自尝试并传播它。至于“关于作者”——如果你感兴趣,请访问“关于”页面。准备好了吗?我们开始吧。

Introduction

简介

There’s plethora of transformative inventions that ended up benefitting humanity as a whole: the Printing Press, Electricity or the Transistor. As for the intellectual commons, there are of course the Linux OS, the World Wide Web protocols, and the concept of Public-Key Cryptography. You know, the stuff we mostly take for granted, or aren’t even aware exists. Tcl, or the “Tool Command Language”, created and released by John Ousterhout in 1990, deserves a place among the greatest products of the human mind. Especially when combined with its better known graphical user interface Toolkit — Tk.

有许多变革性的发明最终造福了全人类:印刷机、电力或晶体管。至于知识共享领域,当然还有 Linux 操作系统、万维网协议以及公钥加密的概念。你知道的,这些是我们大多视为理所当然,甚至根本没意识到其存在的东西。Tcl(即“工具命令语言”)由 John Ousterhout 于 1990 年创建并发布,它理应在人类智慧的最伟大产物中占有一席之地。特别是当它与其更广为人知的图形用户界面工具包 Tk 结合使用时。

In 1997 Ousterhout was awarded the ACM Software System Award for Tcl/Tk, an award given to institutions or individuals recognized for developing software systems with a lasting influence, reflected in contributions to concepts, in commercial acceptance, or both. A good overall summary of what Tcl is could be found in the project’s source code repository: Tcl provides a powerful platform for creating integration applications that tie together diverse applications, protocols, devices, and frameworks. When paired with the Tk toolkit, Tcl provides the fastest and most powerful way to create GUI applications that run on PCs, Unix, and macOS. Tcl can also be used for a variety of web-related tasks and for creating powerful command languages for applications. Tcl is maintained, enhanced…

1997 年,Ousterhout 因 Tcl/Tk 获得了 ACM 软件系统奖,该奖项旨在表彰在开发具有持久影响力的软件系统方面做出贡献的机构或个人,这种影响体现在对概念的贡献、商业认可度或两者兼有。关于 Tcl 是什么的良好总结可以在项目的源代码仓库中找到:Tcl 提供了一个强大的平台,用于创建将各种应用程序、协议、设备和框架连接在一起的集成应用。当与 Tk 工具包配对时,Tcl 提供了在 PC、Unix 和 macOS 上创建 GUI 应用的最快、最强大的方式。Tcl 也可用于各种与 Web 相关的任务,以及为应用程序创建强大的命令语言。Tcl 正在被维护、增强……