This widget is the ttk version of Section 9, “The Checkbutton
widget”. To create a ttk.Checkbutton
widget as the child of a given
widget:parent
w
= ttk.Checkbutton(parent
,option
=value
, ...)
Here are the options for the ttk.Checkbutton
widget. Compare these to the Tkinter version discussed in Section 7, “The Button
widget”.
Table 37. ttk.Checkbutton
options
| The widget class name. This may be specified when the widget is created, but cannot be changed later. For an explanation of widget classes, see Section 27, “Standardizing appearance”. |
| A function to be called whenever the state of this checkbutton changes. |
| This option specifies the relative position of the image relative to the text when you specify both. The value may be
text). If you provide both
for |
| The cursor that will appear when the mouse is over the checkbutton; see Section 5.8, “Cursors”. |
| An image to appear on the checkbutton; see Section 5.9, “Images”. |
| By default, when a checkbutton is in the off (unchecked) state, the value of the associated to specify a different value for the off state. |
| By default, when a checkbutton is in the on (checked) state, the value of the associated to specify a different value for the on state. |
| The style to be used in rendering this checkbutton; see |
| By default, a ttk be included in focus traversal; see Section 53, “Focus: routing keyboard input”. To remove the widget from focus traversal, use |
| The text to appear on the checkbutton, as a string. |
| A variable that controls the text that appears on the checkbutton; see Section 52, “Control variables: the values behind the widgets”. |
| If this option has a nonnegative value n, an underline will appear under the |
| A control variable that tracks the current state of the checkbutton; see Section 52, “Control variables: the values behind the widgets”. Normally you will use an the off and on values are 0 and 1, respectively. However, you may use a different control variable type, and specify the |
| Use this option to specify a fixed width or a minimum width. The value is specified in characters; a positive value sets a fixed width of that many average characters, while a negative width sets a minimum width. For example, if an average character in the selected font is 10 pixels wide, option will make the text label exactly 80 pixels wide; option the length of the text, whichever is larger. You may also specify a an associated style. If values are specified both in the widget constructor call and in the style, the former takes priority. |
These options of the Tkinter Checkbutton
widget
are not supported by the ttk.Checkbutton
widget constructor:
Table 38. Tkinter Checkbutton
options not in
ttk.Checkbutton
| Use a style map to control the changes”. |
| Use a style map to control the |
| Configure this option using a style; see Section 49, “Using and customizing ttk styles”. Use this option to specify the position of the text when the space. For example, if you specify options a checkbutton that displays both text and and image, and a style that specifies (east), the image will be at the right-hand end of the twenty-character space, with the text just below it. When a checkbutton displays an image but no text, this option is ignored. |
| Configure the style. The supported. |
| Not supported. |
| Configure this option using a style. |
| Use a style map for the option; see Section 50.2, “ttk style maps: dynamic appearance changes”. |
| Configure this option using a style. |
| Configure this option using a style. |
| Not supported. |
| To control the color of the focus highlight when the checkbutton does not have focus, use a style map to control the Section 50.2, “ttk style maps: dynamic appearance changes”. |
| You may specify the default focus highlight color by setting this option in a style. You may also control the focus highlight color using a style map. |
| Configure this option using a style. This option may not work in all themes. |
| Not supported. |
| Controls how multiple lines are positioned horizontally relative to each other. Configure this option using a style; values may be
or right-aligned, respectively. |
| Not supported. |
| Use a style map to control the changes”. |
| Not supported. |
| Not supported. |
| Use a style map to control the changes”. |
| Not supported. |
| Not supported. |
| In ttk, there is no option with this name. The state mechanism has been generalized; see Section 50.2, “ttk style maps: dynamic appearance changes”. |
| If you use a style that has this option set to some dimension, the that dimension. |
Methods on a ttk.Checkbutton
include all
those described in Section 46, “Methods common to all ttk widgets”, plus:
.invoke()
This method toggles the state of the checkbutton. If
there is a command
callback, it calls that
callback, and returns whatever value the callback
returned.
Not supported are the following methods of the Tkinter Checkbutton
widget: .deselect()
, .flash()
, .select()
, and .toggle()
. To change the state of a checkbutton
through program control, use the .set()
method of
the associated control variable
.
一键复制
编辑
Web IDE
原始数据
按行查看
历史