My understanding is that ttk widgets have two types of options, which
I will call widget options and style options.
Widget options are those that I can specify, e.g., when I create a
widget, e.g., for a button, I can specify the -text option.
Style options describe the style of a widget and are attributes of the
widget's style but not directly of the widget itself. E.g., background
is a style option for the TButton style. I cannot set the background
for a ttk widget directly. I have to set the background on the
corresponding style.
Question 1:
How do I know the type of an option? For example, -compound seems to
be a widget option. But it might have been a style option. Is it
correct that the docs (http://www.tcl.tk/man/tcl/TkCmd/ttk_button.htm)
list only the widget options?
Question 2:
Is there any documentation of the style options that each ttk widget
takes? I understand that the options differ per theme. To get an idea
what these might be, I listed the element options for each of the
elements of a ttk button. This is what I get:
Button.button element options =
Button.focus element options =
Button.padding element options = ('-padding', '-relief', '-
shiftrelief')
Button.label element options = ('-compound', '-space', '-text', '-
font', '-foreground', '-underline', '-width', '-anchor', '-justify', '-
wraplength', '-embossed', '-image', '-stipple', '-background')
For example, I have not been able to figure out the meaning of the -
shiftrelief and the -stipple options.
Question 3:
These options include widget options (e.g., -text) and style options.
Can an option be a widget option and a style option at the same time?
Question 4:
Is the list of element options displayed above dependent on the
currently active theme? It is clear that the set of element options
used differs per theme.
Question 5:
There are additional style options that are not included in the
element options above: e.g., -font. How can I get a complete list of
these other options?
I am working on a tutorial app - written in Python - that let's people
play around with the different options and see their effects depending
on the selected theme. I am planning to post the app somewhere
publicly. Where should I post it?
Regards,
Andreas
thank you for the good questions.
Here is no expert and others may correct/blame me for the following
words, but it might help...
And here is a TCL user, no Python...
Pre-Note 1:
As a first note, I think, ttk is great software which allows to build
modern applications on modern platforms.
The addressed issue is the one I am struggeling the most.
Pre-Note 2:
Do you know the ttk chapter of tkdocs ? At least, it describes a bit
of introspection but does not answer your questions.
Comments after your questions:
On 4 Jan., 12:01, Andreas L <maps...@googlemail.com> wrote:
> (Note: I am using tk 8.5 with Python 2.7)
>
> My understanding is that ttk widgets have two types of options, which
> I will call widget options and style options.
yes.
> Widget options are those that I can specify, e.g., when I create a
> widget, e.g., for a button, I can specify the -text option.
And what happens, if you don't specify them ? The default values might
be theme specific.
This might happen, because for example, the ttk::label widget might
have a default font named "TkDefaultFont" which might also change with
themes.
> Style options describe the style of a widget and are attributes of the
> widget's style but not directly of the widget itself. E.g., background
> is a style option for the TButton style. I cannot set the background
> for a ttk widget directly. I have to set the background on the
> corresponding style.
This is correct, but the limit between "style" and "widget" is smooth.
ttk::label has a -background option.
If you don't specify a widget option, the theme default might be used.
Thus it is more a "first level" - "second level" with a set of
choices.
In addition, a ttk widget might be composed of subwidgets. It is never
clear, if a widget option applies to all subwidgets etc.
> Question 1:
> How do I know the type of an option? For example, -compound seems to
> be a widget option. But it might have been a style option. Is it
> correct that the docs (http://www.tcl.tk/man/tcl/TkCmd/ttk_button.htm)
> list only the widget options?
Correct.
To find style options:
- ask on this list ;-)
- look to the style definition files (which does not helf if hard-
wired in native widgets (windows/mac)
- I did not find any way of introspection, sorry...
> Question 2:
> Is there any documentation of the style options that each ttk widget
> takes? I understand that the options differ per theme. To get an idea
> what these might be, I listed the element options for each of the
> elements of a ttk button. This is what I get:
> Button.button element options =
> Button.focus element options =
> Button.padding element options = ('-padding', '-relief', '-
> shiftrelief')
> Button.label element options = ('-compound', '-space', '-text', '-
> font', '-foreground', '-underline', '-width', '-anchor', '-justify', '-
> wraplength', '-embossed', '-image', '-stipple', '-background')
>
> For example, I have not been able to figure out the meaning of the -
> shiftrelief and the -stipple options.
Sorry, ask here precisely and someone may answer....
> Question 3:
> These options include widget options (e.g., -text) and style options.
> Can an option be a widget option and a style option at the same time?
Yes, for example "ttk::label -background" which takes the style
default if not specified on the widget side.
> Question 4:
> Is the list of element options displayed above dependent on the
> currently active theme? It is clear that the set of element options
> used differs per theme.
Yes.
One answer I got is:
- background color of frames is even a grafic for some MAC themes and
not a uniform color.
It is a feature, not a bug, but so compkicated, sorry...
>
> Question 5:
> There are additional style options that are not included in the
> element options above: e.g., -font. How can I get a complete list of
> these other options?
See above. I general, I don't know any way.
Hope this helps a bit,
Harald
In some sense, what you are saying is comforting in that I don't seem
to have overlooked any documentation. Yes I came across TkDocs - very
nice but more a tutorial than a reference. I am considering taking a
look at the sources and maybe writing some docs myself.
Andreas