TIP 556: Add oo like widgets to Tk

Bounty program for improvements to Tcl and certain Tcl packages.
Author:         RenĂ© Zaumseil <[email protected]>
State:          Draft
Type:           Project
Vote:           Done
Created:        26-Nov-2019
Keywords:       Tk
Tcl-Version:    8.7
Tk-Branch:      tip-556


New ew oo::class like widgets

::tko::toplevel pathName ?option value? ..

::tko::frame pathName ?option value? ..

::tko::labelframe pathName ?option value? ..

The new widgets will contain the same functionality like the original tk widgets. They are oo:class's and it is possible to add,change and delete methods and options dynamically. The widgets could also be used as oo superclass's.

The interface functions to build new widgets in C are described in tko.3.md.

Tcl widget creation

::oo::class create widgetclass { ::tko initfrom ::tkoclass }

The tko initfrom function is used to create new oo class like widget in Tcl.

Class functions

To provide dynamic option management at class level exists a ::tko function.

::tko initfrom ?::superclass?

::tko optionadd ::classname ?-option dbname dbclass value flags ?body?

::tko optiondel ::classname ?-option? ..

::tko optionget ::classname ?-option? ..

::tko optionset ::classname ?-option {dbname dbclass value flags}? ..

::tko optionhide ::classname ?-option? ..

::tko optionshow ::classname ?-option? ..

Widget methods

To manage options on object level exists an _tko method.

my _tko optionadd -option dbname dbclass value flags ?body?

my _tko optiondel -option ..

my _tko optionhide -option ..

my _tko optionshow -option ..

A detailed description can be found in tko.n.md.


Currently there is no megawidget support core package. These tip will go some steps in this direction. With widgets as oo::class's we can easyly extent existing widgets, just use it as a superclass. The provided functions and methods allow add, delete and changing of options at class and object level. The implementation can be used in C and in Tcl.


A patch implementing these changes is available in the fossil repository in the tip-556 branch.


Documentation is available in md-Format in the .../doc/ directory.

C interface

C-source interface files are in .../generic/tko/. No functionality is currently exported.

C sources

C-source code files are in .../generic/tko/. The new files are added to the makefiles. The calls to the initialization functions are added in tkWindow.c


Test files are available in the .../tests/tko/ directory.

To compare the speed of the new widgets you can run the test frame-30.1. It will compare normal tk, ttk and tko widgets.


See also discussion at the wiki.


Create a new oo tcl widget class: oo::class create myWidget {::tko initfrom ::tko::frame}

Add new methods: oo::define ::myWidget method mycmd {args} {my {*}$args}

Add new class options: ::tko optionadd ::myWidget -o1 o1 O1 v1 {} {set tko(-o1) x}

Add new object options: oo::define ::myWidget method mycmd {args} {my {*}$args} ::myWidget .x .x mycmd _tko optionadd -o2 o2 O2 v2 {} {puts o2=$tko(-o2)}

Open issues

the following funtion from tkoWidget.c should be an tcl::oo function: TclObj *WidgetGetClassName(TclInterp * interp,TclObject object)



This document has been placed in the public domain.