Tk Widgets in Javascript Paper Chapter 3

Implemented Widgets

All Tk widget commands are implemented in namespace ::tk but for compatibility there are interp aliases to be able to use for example button without the ::tk:: namespace prefix for creating a new button instance.

So we have the following commands:

  • ::tk::button
  • ::tk::entry
  • ::tk::frame
  • ::tk::label
  • ::tk::toplevel

From experiments I found out, that you need a


element around most of these widgets to be able to force width and height requirements and also when packing these widgets. So in HTML a button widget would look like so:


The sub commands for a button could not be implemented directly as a namespace ensemble, as the button itself is implemented like an itcl class, so that namespace cannot be additionally be used for a namespace ensemble.

So for example the cget and configure command of a button widget are implemented as ::tk::button::configure and ::tk::button::cget and are handled like itcl class methods. As a result you can use .b1 cget … and .b1 configure ..., if .b1 has been created as a button widget instance using: button .b1 …

But be aware: a Tk widget instance in this implementation is no class object and a sub command of the widget is no class method. It is only handled very similar to these parts, to be able to use common code!

(Part of Tk Widgets in Javascript Paper)