600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > tk图形化界面_图形用户界面:安装Tk

tk图形化界面_图形用户界面:安装Tk

时间:2022-12-06 03:37:23

相关推荐

tk图形化界面_图形用户界面:安装Tk

tk图形化界面

The Tk GUI toolkit was originally written for the TCL scripting language but has since been adopted by many other languages including Ruby. Though it's not the most modern of toolkits, it is free and cross-platform and is a good choice for simpler GUI applications. However, before you can begin writing GUI programs, you first have to install the Tk library and the Ruby "bindings." A binding is the Ruby code used to interface with the Tk library itself. Without bindings, a scripting language cannot access native libraries such as Tk.

Tk GUI工具包最初是为TCL脚本语言编写的,但此后已被包括Ruby在内的许多其他语言采用。 尽管它不是最现代的工具包,但它是免费的且跨平台的,是简单GUI应用程序的不错选择。 但是,在开始编写GUI程序之前,首先必须安装Tk库和Ruby“绑定”。 绑定是用于与Tk库本身接口的Ruby代码。 没有绑定,脚本语言将无法访问本机库,例如Tk。

How you install Tk will vary depending on your operating system.

安装Tk的方式将取决于您的操作系统。

在Windows上安装Tk ( Installing Tk on Windows )

There are numerous ways to install Tk on Windows, but the easiest is to install the ActiveTCL scripting language from Active State. While TCL is a completely different scripting language than Ruby, it's made by the same people who make Tk and the two projects are closely linked. By installing the ActiveState ActiveTCL TCL distribution, you'll also install the Tk toolkit libraries for Ruby to use.

在Windows上有多种安装Tk的方法,但最简单的方法是从Active State安装ActiveTCL脚本语言。 尽管TCL是与Ruby完全不同的脚本语言,但是它是由制作Tk的同一个人制作的,并且两个项目紧密相关。 通过安装ActiveState ActiveTCL TCL发行版,您还将安装Tk工具箱库供Ruby使用。

To install ActiveTCL, go to ActiveTCL's download page and download the 8.4 version of the Standard distribution. Though there are other distributions available, none of them have the features you'll need if you only want Tk (and the Standard distribution is also free). Be sure to download the 8.4 version of the download as the Ruby bindings are written for Tk 8.4, not Tk 8.5. However, this may change with future versions of Ruby. Once it's downloaded, double-click the installer and follow the directions to install ActiveTCL and Tk.

要安装ActiveTCL,请转到ActiveTCL的下载页面,然后下载标准发行版的8.4版本。 尽管还有其他可用的发行版,但是如果您只想要Tk(标准发行版也是免费的),它们都没有您需要的功能。 请确保下载8.4版本的下载内容,因为Ruby绑定是针对Tk 8.4(而非Tk 8.5)编写的。 但是,这可能会随着将来的Ruby版本而改变。 下载完成后,双击安装程序并按照说明安装ActiveTCL和Tk。

If you installed Ruby with the One-Click Installer, then the Ruby Tk bindings are already installed. If you installed Ruby another way and the Tk bindings are not installed, you have two options. The first option is to uninstall your current Ruby interpreter and re-install using the One-Click Installer. The second option is actually far more complicated. It involves installing Visual C++, downloading the Ruby source code and compiling it yourself. Since this is not the normal mode of operation for installing Windows programs, using the One-Click installer is recommended.

如果您使用一键式安装程序安装了Ruby,则已经安装了Ruby Tk绑定。 如果您以其他方式安装了Ruby并且未安装Tk绑定,则有两个选择。 第一种选择是卸载当前的Ruby解释器,然后使用一键安装程序重新安装。 第二种选择实际上要复杂得多。 它涉及安装Visual C ++,下载Ruby源代码并自行编译。 由于这不是用于安装Windows程序的正常操作模式,因此建议使用一键式安装程序。

在Ubuntu Linux上安装Tk ( Installing Tk on Ubuntu Linux )

Installing Tk on Ubuntu Linux is very easy. To install Tk and Ruby's Tk bindings, simply install thelibtcltk-rubypackage. This will install Tk and Ruby's Tk bindings in addition to any other packages needed to run Tk programs written in Ruby. You can either do this from the graphical package manager or by running the following command in a terminal.

在Ubuntu Linux上安装Tk非常容易。 要安装Tk和Ruby的Tk绑定,只需安装libtcltk-ruby软件包。 除了运行用Ruby编写的Tk程序所需的任何其他软件包之外,这还将安装Tk和Ruby的Tk绑定。 您可以从图形包管理器中执行此操作,也可以通过在终端中运行以下命令来执行此操作。

$ sudo apt-get install libtcltk-ruby

Once thelibtcltk-rubypackage is installed, you will be able to write and run Tk programs in Ruby.

安装libtcltk-ruby软件包后,您将能够在Ruby中编写和运行Tk程序。

在其他Linux发行版上安装Tk ( Installing Tk on Other Linux Distributions )

Most distributions should have a Tk package for Ruby and a package manager to handle the dependencies. Refer to your distributions' documentation and support forums for more information, but in general, you will need eitherlibtkorlibtcltkpackages as well as anyruby-tkpackages for the bindings. Alternatively, you can install TCL/Tk from source and compile Ruby from source with the Tk option enabled. However, since most distributions will provide binary packages for Tk and Ruby Tk bindings, these options should only be used as a last resort.

大多数发行版应具有用于Ruby的Tk软件包和用于处理依赖关系的软件包管理器。 有关更多信息,请参考发行版的文档和支持论坛,但通常,您将需要libtklibtcltk软件包以及用于绑定的任何ruby-tk软件包。 另外,您可以从源代码安装TCL / Tk,并在启用了Tk选项的情况下从源代码编译Ruby。 但是,由于大多数发行版将为Tk和Ruby Tk绑定提供二进制包,因此这些选项仅应作为最后的选择。

在OS X上安装Tk ( Installing Tk on OS X )

Installing Tk on OS X is much the same as installing Tk on Windows. Download the ActiveTCL version 8.4 TCL/Tk distribution and install it. The Ruby interpreter that comes with OS X should already have Tk bindings, so once Tk is installed you should be able to run Tk programs written in Ruby.

在OS X上安装Tk与在Windows上安装Tk几乎相同。 下载ActiveTCL版本8.4 TCL / Tk发行版并进行安装。 OS X随附的Ruby解释器应该已经具有Tk绑定,因此一旦安装了Tk,您就应该能够运行用Ruby编写的Tk程序。

测试Tk ( Testing Tk )

Once you have Tk and Ruby Tk bindings, it's a good idea to test it out and make sure it works. The following program will create a new window using Tk. When you run it, you should see a new GUI window. If you see any error messages or no GUI window appears, Tk has not been installed successfully.

一旦有了Tk和Ruby Tk绑定,最好测试一下并确保它可以正常工作。 以下程序将使用Tk创建一个新窗口。 运行它时,您应该看到一个新的GUI窗口。 如果您看到任何错误消息或没有GUI窗口出现,则表明Tk尚未成功安装。

#!/usr/bin/env ruby

require 'tk'

root = TkRoot.new do

title "Ruby/Tk Test"

end

Tk.mainloop

翻译自: /installing-tk-gui-toolkit-2908365

tk图形化界面

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。