Version 26 of Ttk

Updated 2011-03-04 17:40:15 by oehhar

Introduction

Ttk is the Tile extension integrated into Tk as approved in TIP #248 [L1 ].

See http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_intro.htm as well as other Ttk widget pages that can be found at http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm .

Widget pages on wiki:

Themes etc.:

This page details the transition from the existing Tile extension to Ttk functionality inside the Tk source base.

There is no special Ttk package in Tk. It is simply part of Tk 8.5a6+ and will not be made a separate binary library. It will use the ttk:: namespace for the most part, sharing the tk:: namespace and toplevel commands where appropriate. The classic Tk widgets will all be referenceable from the tk:: namespace, in addition to remaining as toplevel commands (for 8.x at least).

See also [L2 ]

JE Also: it's worth considering removing some or all of tk/generic/tkStyle.c (TIP#48 support)


Questions

LV 2007 Nov 01 Bottom line question - if someone wants (or needs) to use a ttk widget, what do they need to do to begin. Would someone who is familar with ttk be willing to write a step by step example of moving a relatively simple application from being an original Tk widget application to an application using Tk and Ttk?


 0.7.8 tile source base       => Tk source base integration (completed 2006-10-30)

 tile:                        => tk
  aclocal.m4                  => ''n/a''
  ChangeLog                   => ''n/a''
  configure*                  => ''n/a''
  configure.in                => ''n/a''
  demos/                      => library/demos/... (''partial'')
  doc/                        => doc/ttk_*
  generic/                    => generic/ttk/...
  library/                    => library/ttk/...
  license.terms               => ''n/a''
  macosx/                     => macosx/...
  Makefile.in                 => ''n/a''
  README.txt                  => ''n/a''
  tclconfig/                  => ''n/a''
  tests/                      => tests/ttk/...
  tools/                      => ''n/a''
  win/                        => win/...

 tile/demos:                  => tk/library/demos/...
  autocomplete.tcl            => ''n/a''
  demo.tcl                    => ttk_demo.tcl
  dirbrowser.tcl              => ''n/a''
  dlgtest.tcl                 => ''n/a''
  iconlib.tcl                 => ttk_iconlib.tcl
  repeater.tcl                => ttk_repeater.tcl
  themes/                     => ''n/a''
  toolbutton.tcl              => ''n/a''

 tile/demos/themes:           => ''n/a''

 tile/doc:                    => tk/doc/...
  Doc files translated to ttk_* with a few exceptions:
  converting.txt              => ''n/a''
  Makefile                    => ''n/a''
  man.macros                  => ''n/a''
  paned.n                     => ttk_panedwindow.n
  tile-intro.n                => ttk_intro.n
  TILE.XML                    => ''n/a''
  tmml.options                => ''n/a''

 tile/generic:                => tk/generic/ttk/...
  altTheme.c                  => ttkDefaultTheme.c
  blink.c                     => ttkBlink.c
  button.c                    => ttkButton.c
  cache.c                     => ttkCache.c
  clamTheme.c                 => ttkClamTheme.c
  classicTheme.c              => ttkClassicTheme.c
  configure*                  => ''n/a''
  configure.in                => ''n/a''
  entry.c                     => ttkEntry.c
  frame.c                     => ttkFrame.c
  gunk.h                      => ''n/a''
  image.c                     => ttkImage.c
  label.c                     => ttkLabel.c
  layout.c                    => ttkLayout.c
  Makefile.in                 => ''n/a''
  manager.c                   => ttkManager.c
  manager.h                   => ttkManager.h
  notebook.c                  => ttkNotebook.c
  paned.c                     => ttkPanedwindow.c
  pkgIndex.tcl.in             => ''n/a''
  progress.c                  => ttkProgress.c
  scale.c                     => ttkScale.c
  scrollbar.c                 => ttkScrollbar.c
  scroll.c                    => ttkScroll.c
  separator.c                 => ttkSeparator.c
  square.c                    => ttkSquare.c
  stepTheme.c                 => ''n/a''
  tile.c                      => ttkInit.c
  tkElements.c                => ttkElements.c
  tkstate.c                   => ttkState.c
  tkTheme.c                   => ttkTheme.c
  tkTheme.h                   => ttkTheme.h
  tkThemeInt.h                => ttkThemeInt.h
  TODO                        => ''n/a''
  trace.c                     => ttkTrace.c
  track.c                     => ttkTrack.c
  treeview.c                  => ttkTreeview.c
  ttk.decls                   => ttk.decls
  ttkDecls.h                  => ttkDecls.h
  ttkStubInit.c               => ttkStubInit.c
  ttkStubLib.c                => ttkStubLib.c
  widget.c                    => ttkWidget.c
  widget.h                    => ttkWidget.h

 tile/library:                => tk/library/ttk/...
  File names remained the same with these exceptions:
  paned.tcl                   => panedwindow.tcl
  stepTheme.tcl               => ''n/a''
  tile.tcl                    => ttk.tcl

 tile/macosx:                 => tk/macosx/...
  aquaTheme.c                 => ttkMacOSXTheme.c

 tile/tclconfig:              => ''n/a''

JE The *.tcl files in tile/tests (except for all.tcl) are mostly small interactive tests that I used during development. There's no real need to import them into the Tk CVS repository.

 tile/tests:                  => tk/tests/ttk/...
  The *.tcl files were removed, other files were moved to the above directory

 tile/tools:                  => tk/tools
  genStubs.tcl                => ''n/a'' Not included yet, needed for Ttk stubs library

 tile/win:                    => tk/win
  makefile.vc                 => ''n/a''
  monitor.c                   => ttkWinMonitor.c
  nmakehlp.c                  => ''n/a''
  rules.vc                    => ''n/a''
  Tile.dsp                    => ''n/a''
  winTheme.c                  => ttkWinTheme.c
  xpTheme.c                   => ttkWinXPTheme.c

KJN Is it intended to supply any demos with Tk 8.5? I'm looking for the demos in 8.5b1, and I can't find them in the locations mentioned above:

 tile/demos:                  => tk/library/demos/...
  demo.tcl                    => ttk_demo.tcl
  iconlib.tcl                 => ttk_iconlib.tcl
  repeater.tcl                => ttk_repeater.tcl

JH The tile demo was designed more as a comparison view for core developers to understand theming. What we need in 8.5 is straight new demos that update the regular demos with fully themed widgets. This is something that we really need to work on for 8.5.0 (and ongoing).


http://www.tkdocs.com/ has begun publishing a series of articles that introduce the reader to tcl and ttk.


http://code.google.com/p/python-ttk/ is a Python package for ttk themed widgets.


  2011-03-04 Wojciech Kocjan answered on clt about custom background color.

HaO Here is the clt post [L3 ] to not loose it. Someone may put it at a better place and format it.

> 1) background color
> Why do some themes don't allow to change the background color. My
> application uses three different backgrounds depending on state:
> warning, error, active. Consider 'warning' when the entered value is
> near some limit, error if its out of limit, active if its currently
> processed.
> I considers this flaw as a no-go.

Yes and no. I agree it is silly you can't just specify background,
especially if you'd use "background" element.
I think it's OSX's theme's fault since you can do that on any platform
except for OSX. I remember seeing some

However, you can easily work around this - I needed a white frame/
label/checkbutton and native frame/label/checkbutton. So, I created
this:

image create photo image_osxWhite -width 16 -height 16
image_osxWhite put \#ffffff -to 0 0 16 16

ttk::style element create OSXWhiteBackground image image_osxBlank16 \
    -border {6 6 6 6} -padding {0} -sticky news
# (although I don't think -border is needed, not sure)

ttk::style layout OSXWhiteFrame {
    OSXWhiteWidget.background

}

ttk::style layout OSXWhiteLabel {
    OSXWhiteWidget.background -children {
        OSXWhiteLabel.label
    }

}

Again, I do agree here that if someone sets -background, it should be
doable.

But I found ttk layouts VERY useful - for example if you want to just
grab the highlighted frame OSX gives you, you can do:

ttk::style layout OSXHighlightedFrame {
    Entry.field

}

bind OSXHighlightedFrame <FocusIn> {%W state focus}
bind OSXHighlightedFrame <FocusOut> {%W state !focus}

And then for the widget:
$path configure -style OSXHighlightedFrame -padding {4 4}
bindtags $path [linsert [bindtags $path] 0 OSXHighlightedFrame]

I create an empty frame for non-OSX, a highlighted frame for OSX and
you can just put widgets in there (like text that doesn't have native
frames) - and they get OSX native frame for free :-)

So, while this particular thing is missing, ttk gives you enough tools
to work around it.

I think the worse thing is lack of introspection - if you want to
"mimic" ttk::checkbutton's default layout, you need to look in OSX
source code and TTK_BEGIN_LAYOUT to get the thing done right.
But, again, I think the advantages overwhelm the problems you can find
with ttk - if you fight such things, my recommendation is to learn ttk
elements, layouts etc.