Differences between revisions 5 and 14 (spanning 9 versions)
Revision 5 as of 2002-09-30 18:25:11
Size: 1518
Editor: starbase
Comment:
Revision 14 as of 2014-03-14 03:48:56
Size: 2840
Comment: update new link
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Describe How Tkinter can exploit Tcl/Tk extensions here.





[...
]




["Tcl"
]/["Tk"] developers have constructed many interesting
[[Tcl]]/[[Tk]] developers have constructed many interesting
Line 14: Line 3:
these--["Tix"], for example--are reasonably well known and these--[[Tix]], for example--are reasonably well known and
Line 16: Line 5:
Tkinter programmers sees a promising Tk extension, is it [[TkInter]] programmer sees a promising Tk extension, is it
Line 22: Line 11:
sets, most notably including ["BWidgets"] and ["tklib"], are sets, most notably including [[BWidgets]] and [[tklib]], are
Line 27: Line 16:
These extensions are nearly as easy for Tkinter programmers
to use. Here's an example: . . .
These extensions are nearly as easy for [[TkInter]] programmers
to use. Here's an example:
Line 30: Line 19:
If you have a file of Tcl code in a file called foo.tcl
and you want to call the Tcl function foo_bar then
{{{
    import Tkinter
    root = Tkinter.Tk()
    root.tk.eval('source {foo.tcl}')
    root.tk.eval('foo_bar')
}}}
Line 31: Line 28:
will load and execute foo_bar. To see the details of passing and
returing arguments, Use the Source Luke, and look at Lib/lib-tk/Tkinter.py.
For wrappers of other popular Tk widgets, look at the Python/ directory
of the Tixapps distribution http://tix.sourceforge.net/Tixapps/
Line 32: Line 33:
On the other hand, [[Tix]] and [[BLT]] are popular Tk extensions which
require compilation. These days (since version 8.0 of Tk) most extensions
are compiled as dynamic loading packages, and are as easy to load into
Tkinter as pure Tk extensions using a Python expression like
Line 33: Line 38:
{{{
    root.tk.eval('package require Ext')
}}}
Line 34: Line 42:
For an example of this, see the Lib/lib-tk/Tix.py file in the standard
library that loads the [[Tix]] extension.
Line 35: Line 45:
The trick here is to install the extension library directory in a place the
Tcl in [[TkInter]] will find it. The best place to try is as a subdirectory
of Tcl/ in the Python installation. If this does not work, look into
the file pkgIndex.tcl in the extension's library directory and try to
understand what it is doing to load the .dll or .so shared library.
To ask Tcl to consider a specific directory that contains a package, use
Line 36: Line 52:
















On the other hand, Tix and ["BLT"] are popular Tk extensions which
require compilation. . . .





{{{
     root.tk.eval('lappend auto_path {%s}' % the_tcl_directory)
}}}
Line 63: Line 58:
["Fredrik Lundh"] has pages which he calls "work in progress", but FredrikLundh has pages which he calls "work in progress", but
Line 65: Line 60:
http://effbot.org/zone/bwidgets.htm (http://effbot.org/zone/bwidgets.htm is gone Fredrik recommends http://tkinter.unpythonic.net/bwidget/ )
Line 70: Line 65:
is likely to show up in the Tcl-ers' Wiki
[http://wiki.tcl.tk/tkinter Tkinter].
is likely to show up in the Tcl-ers' Wiki for
[[http://wiki.tcl.tk/tkinter|Tkinter]].

Tcl/Tk developers have constructed many interesting widget sets which extend Tk's basic functionality. A few of these--Tix, for example--are reasonably well known and accessible to Tkinter users. What about the rest? When a TkInter programmer sees a promising Tk extension, is it likely to do him or her any good?

Briefly, yes. First, it's important to make the distinction between so-called "pure Tk" extensions and those that involve (external) C-coded compilation. Quite a few useful widgets sets, most notably including BWidgets and tklib, are "pure Tk". That means that Tcl/Tk programmers simply read them in at run time, with no need for (re-)compilation, configuration, or other deployment complexities.

These extensions are nearly as easy for TkInter programmers to use. Here's an example:

If you have a file of Tcl code in a file called foo.tcl and you want to call the Tcl function foo_bar then

    import Tkinter
    root = Tkinter.Tk()
    root.tk.eval('source {foo.tcl}')
    root.tk.eval('foo_bar')

will load and execute foo_bar. To see the details of passing and returing arguments, Use the Source Luke, and look at Lib/lib-tk/Tkinter.py. For wrappers of other popular Tk widgets, look at the Python/ directory of the Tixapps distribution http://tix.sourceforge.net/Tixapps/

On the other hand, Tix and BLT are popular Tk extensions which require compilation. These days (since version 8.0 of Tk) most extensions are compiled as dynamic loading packages, and are as easy to load into Tkinter as pure Tk extensions using a Python expression like

    root.tk.eval('package require Ext')

For an example of this, see the Lib/lib-tk/Tix.py file in the standard library that loads the Tix extension.

The trick here is to install the extension library directory in a place the Tcl in TkInter will find it. The best place to try is as a subdirectory of Tcl/ in the Python installation. If this does not work, look into the file pkgIndex.tcl in the extension's library directory and try to understand what it is doing to load the .dll or .so shared library. To ask Tcl to consider a specific directory that contains a package, use

     root.tk.eval('lappend auto_path {%s}' % the_tcl_directory)


FredrikLundh has pages which he calls "work in progress", but which readers are certain to find helpful: (http://effbot.org/zone/bwidgets.htm is gone Fredrik recommends http://tkinter.unpythonic.net/bwidget/ ) and http://effbot.org/zone/tkinter-text-bind-insert-delete.htm The latter explicitly extends Tkinter through use of Tcl. Also, Gustavo Cordero is working in this same area; his work is likely to show up in the Tcl-ers' Wiki for Tkinter.

How Tkinter can exploit Tcl/Tk extensions (last edited 2014-03-14 03:48:56 by DaleAthanasias)

Unable to edit the page? See the FrontPage for instructions.