Perform minor copy edits

This commit is contained in:
Raymond Hettinger 2009-04-08 08:23:44 +00:00
parent 4c0b1e4026
commit 238018c5c4
1 changed files with 37 additions and 40 deletions

View File

@ -9,13 +9,13 @@
.. index:: single: ttk .. index:: single: ttk
The :mod:`tkinter.ttk` module provides access to the Tk themed widget set, The :mod:`tkinter.ttk` module provides access to the Tk themed widget set,
which has been introduced in Tk 8.5. If you do not have Python compiled against introduced in Tk 8.5. If Python has not been compiled against Tk 8.5, this
Tk 8.5 you may still use this module as long as you have Tile installed, but module can still be accessed if *Tile* has been installed. The former
then you will miss some features provided by the new Tk, like anti-aliased font method using Tk 8.5 provides additional benefits including anti-aliased font
rendering under X11, window transparency (on X11 you will need a composition rendering under X11 and window transparency (requiring a composition
window manager) and others. window manager on X11).
The basic idea of :mod:`tkinter.ttk` is to separate, to the extent possible, The basic idea for :mod:`tkinter.ttk` is to separate, to the extent possible,
the code implementing a widget's behavior from the code implementing its the code implementing a widget's behavior from the code implementing its
appearance. appearance.
@ -23,58 +23,55 @@ appearance.
.. seealso:: .. seealso::
`Tk Widget Styling Support <http://www.tcl.tk/cgi-bin/tct/tip/48>`_ `Tk Widget Styling Support <http://www.tcl.tk/cgi-bin/tct/tip/48>`_
The document which brought up theming support for Tk A document introducing theming support for Tk
Using Ttk Using Ttk
--------- ---------
Basically, to start using Ttk, you have to import its module:: To start using Ttk, import its module::
from tkinter import ttk from tkinter import ttk
But if you already have some code that does:: To override the basic Tk widgets, the import should follow the Tk import::
from tkinter import *
You may optionally want to use::
from tkinter import * from tkinter import *
from tkinter.ttk import * from tkinter.ttk import *
And then several :mod:`tkinter.ttk` widgets (:class:`Button`, That code causes several :mod:`tkinter.ttk` widgets (:class:`Button`,
:class:`Checkbutton`, :class:`Entry`, :class:`Frame`, :class:`Label`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`, :class:`Label`,
:class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`, :class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`,
:class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`) will :class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`) to
automatically substitute the Tk widgets. automatically replace the Tk widgets.
This has the direct benefit of using the new widgets which gives a better
look and feel across platforms; however, the replacement widgets are not
completely compatible. The main difference is that widget options such as
"fg", "bg" and others related to widget styling are no
longer present in Ttk widgets. Instead, use the :class:`ttk.Style` class
for improved styling effects.
This has the direct benefit of using the new widgets which gives better
look & feel across platforms, but you should be aware that they are not
totally compatible. The main difference you will find out is that widget
options such as "fg", "bg" and others related to widget styling are no
longer present in Ttk widgets, instead you will have to use :class:`ttk.Style`
to achieve the same (or better) styling.
.. seealso:: .. seealso::
`Converting existing applications to use the Tile widgets <http://tktable.sourceforge.net/tile/doc/converting.txt>`_ `Converting existing applications to use Tile widgets <http://tktable.sourceforge.net/tile/doc/converting.txt>`_
A text which talks in Tcl terms about differences typically found when A monograph (using Tcl terminology) about differences typically
moving applications to use the new widgets. encountered when moving applications to use the new widgets.
Ttk Widgets Ttk Widgets
----------- -----------
Ttk comes with 17 widgets, where 11 of these already existed in tkinter: Ttk comes with 17 widgets, eleven of which already existed in tkinter:
:class:`Button`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`, :class:`Button`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`,
:class:`Label`, :class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`, :class:`Label`, :class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`,
:class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`. The others 6 are :class:`Radiobutton`, :class:`Scale` and :class:`Scrollbar`. The other six are
new: :class:`Combobox`, :class:`Notebook`, :class:`Progressbar`, new: :class:`Combobox`, :class:`Notebook`, :class:`Progressbar`,
:class:`Separator`, :class:`Sizegrip` and :class:`Treeview`. And all them are :class:`Separator`, :class:`Sizegrip` and :class:`Treeview`. And all them are
subclasses of :class:`Widget`. subclasses of :class:`Widget`.
Like it was told before, you will notice changes in look & feel as well in the Using the Ttk widgets gives the application an improved look and feel.
styling code. To demonstrate the latter, a very simple example is shown below. As discussed above, there are differences in how the styling is coded.
Tk code:: Tk code::
@ -90,7 +87,7 @@ Ttk code::
l1 = ttk.Label(text="Test", style="BW.TLabel") l1 = ttk.Label(text="Test", style="BW.TLabel")
l2 = ttk.Label(text="Test", style="BW.TLabel") l2 = ttk.Label(text="Test", style="BW.TLabel")
For more information about TtkStyling_ read the :class:`Style` class For more information about TtkStyling_, see the :class:`Style` class
documentation. documentation.
Widget Widget
@ -554,10 +551,10 @@ Progressbar
----------- -----------
The :class:`ttk.Progressbar` widget shows the status of a long-running The :class:`ttk.Progressbar` widget shows the status of a long-running
operation. It can operate in two modes: determinate mode shows the amount operation. It can operate in two modes: 1) the determinate mode which shows the
completed relative to the total amount of work to be done, and indeterminate amount completed relative to the total amount of work to be done and 2) the
mode provides an animated display to let the user know that something is indeterminate mode which provides an animated display to let the user know that
happening. work is progressing.
Options Options
@ -1164,7 +1161,7 @@ option. If you don't know the class name of a widget, use the method
the value for that option. the value for that option.
For example, to change every default button to be a flat button with For example, to change every default button to be a flat button with
some padding and a different background color you could do:: some padding and a different background color::
from tkinter import ttk from tkinter import ttk
import tkinter import tkinter
@ -1186,7 +1183,7 @@ option. If you don't know the class name of a widget, use the method
Each key in *kw* is an option and each value should be a list or a Each key in *kw* is an option and each value should be a list or a
tuple (usually) containing statespecs grouped in tuples, lists, or tuple (usually) containing statespecs grouped in tuples, lists, or
something else of your preference. A statespec is a compound of one some other preference. A statespec is a compound of one
or more states and then a value. or more states and then a value.
An example may make it more understandable:: An example may make it more understandable::
@ -1208,9 +1205,9 @@ option. If you don't know the class name of a widget, use the method
Note that the order of the (states, value) sequences for an option does Note that the order of the (states, value) sequences for an option does
matter, if you changed the order to ``[('active', 'blue'), ('pressed', matter, if the order is changed to ``[('active', 'blue'), ('pressed',
'red')]`` in the foreground option, for example, you would get a blue 'red')]`` in the foreground option, for example, the result would be a
foreground when the widget were in active or pressed states. blue foreground when the widget were in active or pressed states.
.. method:: lookup(style, option[, state=None[, default=None]]) .. method:: lookup(style, option[, state=None[, default=None]])
@ -1221,7 +1218,7 @@ option. If you don't know the class name of a widget, use the method
states. If the *default* argument is set, it is used as a fallback value states. If the *default* argument is set, it is used as a fallback value
in case no specification for option is found. in case no specification for option is found.
To check what font a Button uses by default, you would do:: To check what font a Button uses by default::
from tkinter import ttk from tkinter import ttk