, which is the main window of the application. At the top of this hierarchy we have a widget called. is the name of a widget that is child of widget. These names are hierarchical in the same way as file system names are, but "." is used instead of "/" to separate levels. The widgets are identified by path names of the form. The windows and controls that make up a Tk interface are called widgets. Because of this we almost always use objects when working with Tkx widgets. Or Tkx.b_configure(-text => "Goodbye, cruel world") īut neither of those work as you can't use "." as part of function names in Perl. b configure -text "Goodbye, cuel world"Ī literal translation to Tkx would be: Tkx.b("configure", -text => "Goodbye, cruel world") For example, if you want to change the text of the button created above you might in Tcl do. Ī major complication in the mapping to Perl is how to invoke subcommands on Tk widgets. The ActiveTcl HTML documentation can also be downloaded from and installed locally. This documents core Tk and useful add-on packages that are part of ActiveTcl. This translation is relatively straightforward and basically involves adding the prefix "Tkx::" to all the functions and passing arguments with Perl syntax (as with the Tkx::button examples above). Instead you will need to read the mostly excellent documentation that comes with Tcl/Tk and extrapolate the Tkx syntax. Tkx does not include documentation for all the Tk widgets available for use. The only difference is that the call to MainLoop() is implicit in Tcl and does not have to be spelled out. As you can see the code is mostly identical, but with a slightly different syntax. This program can be executed by the tclsh binary that comes with Tcl/Tk. In this case the callback destroys the window, which in turn terminates the application.įor reference, this is how the same program would look in Tcl: package require Tk Clicking the button will invoke the subroutine registered with the button's -command option. This is done with the Tkx::MainLoop() call at the end. After the layout of the window has been set up, we need to pass control back to Tk so that it can draw the window and invoke our callback if the button is clicked. We create a button with the name ".b" and tell the window to display the button with the call to Tkx::pack(). Let's look at what this code is doing.Īfter the Tkx module has been loaded by the use Tkx statement, the application will show an empty window called ".". A window with the text "Hello, world" should appear on your screen. Save this to a file called and then run perl to start the application. The code to make this happen is: use Tkx We'll make the application window contain a single button which will shut down the application if clicked. Let's start with the mandatory exercise of creating an application that greats the world. By loading the Tkx module Perl programs can create windows and fill them with text, images, buttons and other controls that make up the user interface of the application. Tkx is a Perl module that makes the Tk toolkit available to Perl programs. The Tk toolkit is native to the Tcl programming language, but its ease of use and cross-platform availability has made it the GUI toolkit of choice for many other dynamic languages. Tk is a toolkit for creating applications with graphical interfaces on Windows, Mac OS X and X11. Tkx::Tutorial - How to use Tkx DESCRIPTION
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |