Version 30 of NexTk

Updated 2007-11-06 09:05:00 by GPS

So, is NexTk a next generation exploration of Tk ? Just trying to understand what it actually is. I don't have a machine available to try the code right now.

It's a next generation implementation of Tk. -GPS

NexTk is available with a massive collection of code here:

Steps to get it running (albeit with a silly demo at the moment):

  1. svn checkout megapkg
  2. cd megapkg
  3. cp build.conf build.conf.whatever
  4. edit build.conf.whatever (you may need to install development packages for Freetype, libpng, libjpeg, X11, Xv, XShm)
  5. tclsh8.5 build.tcl build.conf.whatever unix
  6. tclsh8.5 build.tcl build.conf.whatever NexTk_demo.kit (for historical reasons that doesn't actually generate a starkit. It just copies the build directory contents to NexTk_demo.vfs/lib.
  7. cd NexTk_demo.vfs
  8. sh
  9. sh
  10. wish8.5 main.tcl
  11. Send me patches!

You can also try the NexTk_image_viewer.vfs that uses ntk (it's only a few days old). After running the previous steps do:

  1. cd NexTk_image_viewer.vfs
  2. sh (the script by default copies the Linux build tree, for BSD you'll need to edit it)
  3. tclsh8.5 main.tcl

(Corrected Oct 4, 2007)

C'est la vie

I regret to some extent getting involved with Tcl and Tk years ago.

RLH Why would you say something like that?

George, I understand your frustration. However, note that little attention to anything related to Tcl/Tk 9 has been given, to date. Right now, the focus has been Tcl/Tk 8.5 (and probably 8.6).

Hang in there - hang onto the code. I suspect that, once 8.6 is out, attention will begin to turn towards 9.x series.

George Peter Staplin 2007.09.20 : I plan to do that. Thank you. NexTk is alive, and I'm working on improve Tcl again, and especially extending it for amazing graphical capabilities.

KJN 2007.09.20 : Are the Enlightenment E17 libraries of any use? They are BSD licensed, and do 2D graphics with transparency and animation. The Enlightenment live CD has some good demos, but the best item is not switched on by default (you have to search for it) - an animated taskbar like the one in OS X.

George Peter Staplin 2007.09.20 : Hi KJN, are the Enlightenment libraries portable? I've been working the last week or 2 on a new Tcl extension called ntk in megapkg. It provides Win32, X11, and hopefully in the future Mac OS X compatibility. More on ntk below (under NEWS).

KJN 2007.09.20 : I'm no expert, but the Evas (Enlightenment Canvas) has several "engines" (backends). Recent CVS commits [L1 ] have these log entries:

  • "Glew OpenGL engine added. Windows can have an opengl engine thgough the Glew library, now. See INSTALL note" (the note refers to the Glew library and compilation with MinGW)
  • "Direct3D engine. I'm not an expert of that api, so there should room for lots of improvements"
  • "added per-engine pc files" - as well as Glew and Direct3D, the engines include SDL and ddraw. The engines are in [L2 ] and also include win32_gdi.

I haven't tried to build and run Evas with any of these engines, so I don't know how complete they are - but it is clear that the project is actively developing backends for several different platforms.

George Peter Staplin 2006.07.11 : As the Tcl/Tk core team is taking their time with Tk 8.5, I've been working on my own Tk9 for a few months. (Now named NexTk) It implements a window system using Tcl, and some C extensions from megapkg (megaimage, megaimagetk, structure). It has full support for alpha transparency in any widget. You can rotate windows, and every color in Tk9 consists of [list R G B A].

Features so far include (from megaimage):

  • antialiased line drawing using Wu's algorithm (full RGBA support).
  • rectangle drawing (full RGBA support)
  • rotation
  • scaling
  • arbitrary pixel put/get
  • getrow/putrow
  • and much much more! :)


George Peter Staplin 2007.11.06 : The NexTk_image_viewer now uses the ntk_panedwindow widget. The panedwindow widget is new and supports -orient horizontal and vertical. The scrollbar has had a lot of polishing done.

Some other new widgets are ntk_checkbox and ntk_spinbox. They are pretty much complete, and work well.

The text widget is now using some ideas from Zarutian. He suggested separating the data from the metadata. I think it's cleaner this way, and much easier to program. I'm slowly improving the text widget, as its design evolves.

I took input from KBK on the listbox widget, and added a 3D appearance to the listbox. I updated the image viewer screenshot below.

I found a way to reduce the memory requirements by almost a third, by reducing the temporary buffers used in rendertree.tcl. One thing to keep in mind is that NexTk in combination with ntk keeps most of the buffers that Tk would use, on the client side. It may seem at times like NexTk is using more memory than a typical app, but that's because, Pixmap and Window buffers in X11 are stored on the server side with most toolkits.

I have some ideas for improving the speed of tclTimer.c that will probably be implemented soon and I hope make it into 8.6.

apw is working a lot on ntkWidget. I've tried some of his demos, and they work. He's been spending a lot of time on OpenGL ideas. He has taken a thing called GLFW and added multiple window support, and other features, to enable working with megaimages. Based on what we've talked about FBOs or frame buffer objects are in the future. He also wrote a cool script for his tclGL that translates the OpenGL API from header files to Tcl commands.

I'm also working occasionally on glimage, which is meant to have a higher level API and not look so much like OpenGL.

Slow, but steady progress. I'm not going to burn out.

Here's a screenshot of NexTk's panedwindow, checkbutton, button, label, and spinbox:

George Peter Staplin 2007.10.16 : Well, we now have the NexTk image viewer working quite well. It views JPEG and PNG images, and supports drag scrolling of large images.

The listbox has had a lot of changes, as well as the scrollbar since the last update. I've also been working a lot on ntk. The ntk_listbox and ntk_scrollbar now do proper scrolling in all of the cases of the image viewer. Left to add are page-relative scrolling (if desired), I'm still not sure. We also need to theme the scrollbar sliders. At the moment they are just rectangles.

apw has been doing a lot of work on his version of NexTk based on mine. We're working together to improve the future Tks.

I've been also working on megaimage3d, and structure. I made ntk display its first window in NT 4, and it works in XP as well. The Over and Out game has been reimplemented. It's now much cleaner/simpler.

Here's a screenshot of the image viewer:

George Peter Staplin 2007.09.27 : Some of the NexTk extensions helped power the 2007 Tcl Conference! Yay! megaimage has some new features that rmax requested. The extensions used were megaimage, jpegext2, and freetypeext.

I've done a lot of work on the freetypeext recently, and ntk.

Ntk is moving along. I now have it displaying megaimages in X11, calling Tcl-side callbacks on buttonpress, buttonrelease, keypress, motion, and configure events, redrawing automatically on Expose, and more. I have a TODO setup for anyone that wants to help here:

I've talked with Pat Thoyts about Win32 support. I'm hoping he will be able to help. If not, I'll just continue on my path to use the DIB layer in Windows. I'm hoping that someone more experienced with Win32 will be able to help with DirectX.

apw is working on using his itcl-ng to power NexTk. I feel that this may be a better direction than using the structure extension that NexTk currently uses, and I'm glad to have his help.

I rewrote the rendertree extension in Tcl, and I've managed to get better performance. The code is also more understandable. You can see how I've done it here:

I have started work on the NexTk scrollbar. The buttons work well so far. I'm using ntk_grid to manage the scrollbar components. More work will be done on this soon.

Here is a screenshot of the latest revision of the demo (using megaimagetk under X11):

George Peter Staplin 2007.09.20 : I fixed widget destruction handling, and a long standing bug that went unnoticed in the structure extension. A new extension called ntk is being written for Win32 and X11. Ntk is going to replace the Tk layer currently used by NexTk and the megaimagetk widget.

Ntk (.dll/.so) provides:

  • event handling for Win32 and X11 that evaluates Tcl-side callbacks.
  • fast megaimage display using XShm and DBE with X11
  • selection control (copy/paste)
  • the ability to create system windows to host NexTk windows.
  • window destruction
  • window movement/resize requests

I've started writing a game like Richard's Over and Out for NexTk. I also have the start of a 3D rotating box that is kind of neat. The text widget data structure code has been tested, and I believe I found a good solution that is very scalable based on my measurements. The format for a line is:

 set line [list $linewidth $lineheight [list $context text] [list $anothercontext text]]

And each line is a member of a list. So it's like:

 set body [list $line1 $line2]

Then the body gets stored in a structure. I've tested it with over 10,000 lines of text from one of Edgar Allen Poe's works, and it's quick, so I think it's scalable enough. The real cost and difficulty may be getting freetypeext to be fast enough at measuring, that we can have proper scrolling even with wrapped text.

The grid manager has been rewritten, and with some input from the Tk core grid maintainer I have fixed some bugs. It doesn't use any idle handlers, so I think it's superior to Tk's grid.

I started on a scrollbar, and ended up writing some generic code in theme.img for drawing 3D reliefs. Eventually the button.img should use that code in theme.img.

Caveat the demo is kind of a mess of unfinished code, and once the ntk extension is finished I'll write some real applications that are better than the demo.


If any of you are in the Tcler's Chat occasionally you may have noticed I've improving the performance of NexTk drastically.

A few things of interest: I fixed a bug in the structure extension. It wasn't freeing the internal rep of some shimmered objects, so this fixed a few leaks. I rewrote proc rendertree in C. I've drastically improved the speed of megaimage_blend, and megaimage_rotate. We now have an optional -DFAST_BLEND that uses a rather large lookup table for alpha blending. I wrote a listbox widget. It's still somewhat primitive, but it works. I added a -fullscreen flag. New Starkits will probably appear soon, once I've made a bit more progress. There have been changes throughout the tk9.vfs/NexTk tree that are too numerous to mention. The grid manager is used with the image selection window in the demo, and I'm pleased by grid.img for the first time.

Only parts of the tree changed will be re-rendered now. This has greatly improved performance.

I've got a working, but slow, megaimage3d. This may soon showup in the demo.

I'm working on an Nvidia driver for my GeForce 2 card. This will allow me to run NexTk without X.

Here's a screenshot:


After some help testing from Tcler's Chat people, I now think I have fixed the bug that occured sometimes with Xv (X video extension) and some video cards. I worked on my initial prototype program again to figure out the bug. This is the prototype:

I then added that code and did a round of builds. This time I did the Linux builds in Debian Sarge within Qemu. There was a bit of a strange libm issue that Torsten noticed otherwise I think. I tested in Windows, NetBSD, and with SuSE Linux emulation in NetBSD.

The latest demo is here and requires Tclkit >= 8.5a4:

If the Xv code still fails, don't fret, because you can run the demo! (Please let me know if it does fail, because it's supposed to automatically fallback to MIT-SHM.) You can do:

 tclkit8.5 NexTk_demo5b.kit

  1. We now have a working button widget.
  2. We have a mostly complete grid. I want to talk with KBK about linear programming and grid management.
  3. The input system has had further improvements.
  4. I fixed 2 bugs in the Xvideo support.
  5. I added support for the NEXTK_DISABLE_XV. To use it just do: export NEXTK_DISABLE_XV=1

(for further changes see the megapkg CHANGES file)

  1. I did more work on using this code as a window system in NetBSD without X.
  2. I added documentation for megaimage and megaimagetk.

Here's a new screenshot:


  1. I created a new Starkit for NetBSD, Linux, and Windows XP x86.
  2. Windows support now includes Freetypeext (for the text display).
  3. It has support for text input in rotated widgets. This was a rather difficult thing to add at first.
  4. I added Xv support to the persistent rendering widget, so that now we have accelerated rendering for some video cards. If xvinfo says that your video card supports YUY2 then it should work. I'm going to add other formats, but it takes a while to learn the way.
  5. The entry widget appears in this release (as a white box in the red window). It has support for cursor positioning with the mouse, keyboard, and backspace/delete support. The mouse cursor positioning is off when the widget scrolls due to the contents not fully being on screen. This will be fixed.
  6. This is the first release to use the new grid manager. It's not perfect in all cases yet, but it will become better with use and changes I make overtime.
  7. I made some rendering improvements, and performance improvements, and I still want to make more.

Here is a screenshot from that Starkit:

  1. Apply some of the ideas that Torsten suggested.
  2. Speedup the rendering by possibly exporting some of the structure extension, and doing more of it in C. Right now the core loop of the compositor is written in Tcl (proc rendertree).
  3. Create a clock widget.
  4. Create a button widget.


  1. I almost have the entry widget fully functional.
  2. I changed the rendering engine to improve performance and quality.
  3. I added YUY2 image support for use with the Xv X extension. This means that we get some hardware assistance when rendering.
  4. The input subsystem is now being used in the demo, and being fed by some 8.5 compat code.

Here's a new screenshot:

Items left to do:

  1. Input system changes for supporting rotated widgets in the -buttonpress structure element callbacks. This will involve taking into account all of the rotations of windows and subwindows.
  2. Make the entry widget resize its container properly for the height of the text.
  3. Documentation for the extensions.
  4. Demo changes to allow the user to create new windows, with images, or without.


I have ported the base widget that hosts Tk9 within Tk8.x to Windows. I'm now regularly building Windows DLLs with the MinGW cross compiler from pkgsrc. There are many changes I've made to the C extensions. I also had to modify the tk9_demo.vfs files to work in Windows, and created an archmap.tcl for having the Starkit support multiple platforms.

Here's a link to the Starkit that supports NetBSD x86, Linux x86, and Windows for 8.5a4 tclkits:

Thanks to Pat Thoyts and RS for testing in Windows, and elsewhere.

DKF suggested that I change the name to NexTk1. I like the sound of NexTk.

I'm thinking seriously about finishing my notes on the nv driver for X, so that I can mmap the memory, setup the card, and use this as my window system. I was thinking that I could use a modified Xvfb with this code to support X11 apps in my own window system.

It's probably time to profile the code in the demo. Some hot spots may exist in the C code or the demo itself. The grid engine is basically finished for now I think. Once I get it working in real world apps I think that will be the real test of it.

Freetypeext was almost completely rewritten recently. I also added more tests for it, and leak tests that have eliminated all leaks.


I created a new demo for x86 Linux (requires an 8.5 tclkit):

The mouse input and dragging works perfectly now with rotated tk9_windows. Now you can rotate any window in the demo. Just select the window and click the Tk8.x Rotate button at the bottom. This release is the first that demonstrates the Freetype font feature (only used if you have Vera.ttf).

Thanks to Gerald W. Lester for his help with the rotated-window-mouse-input algorithm, and the developers of the tcllib math package for the excellent point-in-polygon code that I used.

We can also now rotate windows over and over again with only a single rotations loss. This is the first tk9_demo to use the tk9.vfs and what will become the standard window.img.

I've updated the plans here:

Thanks to rdt for testing the demo in Linux. I build the starkits with qemu, and test with an 8.5 Tclkit from Linux via NetBSD's Linux emulation.

The grid manager is also at revision 4 in the 2nd prototype. It's moving along and the results are good.


I have a working prototype of

Sample code that generated that is available here:

I plan to add kerning support, so that the text has better spacing between chars. Also see the text_playground.tcl file for further features I want to add that will be required for things like entry and text widgets.

I've started on my second prototype of a grid manager in Tcl. It now has -columnspan, -rowspan, and -sticky.

A little work everyday adds up to a lot.

At the moment it uses megaimagetk's megaimage.frame (in the demo) for fast shared memory image display. Future performance will be even better.

I have a demo/prototype that you can drag around the windows in, and watch as the alpha transparency works flawlessly with the windows.

Here's an example of the Tk9 demo (prototype WIP):

Download the demo (for x86 Linux (built in Debian Sarge)): (removed due to lack of disk quota space)

Design Plans for Tk9

Future Features

  • megaimage polygon code
  • a new grid manager implemented in Tcl (work in progress)
  • complete window.img and use it in the demo.
  • better handling of alpha transparency when dragging rotated objects in the demo.
  • port to a bare framebuffer and use it as an alternative to X11 (possibly via VESA support).

I'm open to new developers helping. Are any of you interested in a mailing list?

I'm looking forward to this when I get one of them thar' round toits.

How on earth do you get this thing running on Win2k?

Category GUI