30. ttk.Checkbutton
This widget is the ttk version of Section 9 “Widgets”. To create a ttk widget as a child of a given widget: Checkbutton.Checkbutton
parent
w= ttk.Checkbutton(parent, option= value, ...)
The following are the options for the ttk widget .Checkbutton
. Compare them to the Tkinter version discussed in Section 7, “Widgets”. Button
Table 37. ttk.Checkbutton
Options
class_ |
Widget class name. This can be specified when the widget is created, but cannot be changed later. See Section 27, “Standardized Appearance” for a description of widget classes. |
command |
Function that will be called whenever the state of this checkbox changes. |
compound |
This option specifies the relative position of the image relative to the text when you specify both. The value can be tk.TOP (image above text), tk.BOTTOM (image below text), tk.LEFT (text image to the left) or tk.RIGHT (image to the right of the text). If you provide both the image and text options without specifying a value for compound , only the image is displayed. |
cursor |
The cursor that appears when the mouse is over a check button; see Section 5.8, “Cursors”. |
image |
The image that appears on the check button; see Section 5.9, “Images”. |
offvalue |
By default, when a check button is off (unchecked), the associated value is variable 0. You can use the offvalue option to specify a different value for the off state. |
onvalue |
By default, when a check button is on (selected), the associated value is variable 1. You can use the onvalue option to specify a different value for the open state. |
style |
The style to use when rendering this checkbox; see Section 49, “Using and Customizing ttk Styles”. |
takefocus |
By default, a ttk is included in the focus traversal;.Checkbutton See Section 53, “Focus: Routing Keyboard Input”. To remove a widget from focus traversal, use takefocus=False . |
text |
Text to display on the check button, as a string. |
textvariable |
Variable that controls the text displayed on the check button; see Section 52, “Controlling Variables: The Value Behind the Widget”. |
underline |
If this option has a non-negative value ntext , an underline will appear below the character at position n. |
variable |
Control variable that tracks the current state of the check button; see Section 52, “Control Variables: Values Behind Widgets”. Typically you would use an IntVar here, with off and on values of 0 and 1 respectively. However, you can use a different control variable type and specify the offvalue and onvalue options with a value of that type. |
width |
Use this option to specify a fixed width or a minimum width. The value is specified in characters; positive values set a fixed width across multiple average characters, while negative values set the minimum width. For example, if the average character in the selected font is 10 pixels wide, the option
|
The ttk widget constructor does not support these options for the Tkinter Checkbutton
widget: .Checkbutton
Table 38. Tkinter not available in ttkTkinter Checkbutton
options .Checkbutton
activebackground |
Use style diagrams to control background option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
activeforeground |
Use style map to control foreground options. |
anchor |
Configure this option using styles; see Section 49, “Using and Customizing ttk Styles”. Use this option to specify the position of text For example, if you specify the options This option is ignored when the checkbutton displays an image but no text. |
background or bg |
background Use style configuration options. bg does not support abbreviations. |
bitmap |
Not supported. |
borderwidth or bd |
Configure this option using styles. |
disabledforeground |
Use style map as foreground option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
font |
Configure this option using styles. |
foreground or fg |
Configure this option using styles. |
height |
Not supported. |
highlightbackground |
To control when the check button has no focus The color of the focus highlight, use a style map to control the option highlightcolor ; see Section 50.2, “TTK Style Map: Dynamic Appearance Changes”. |
highlightcolor |
You can set this option in the style to specify the default focus highlight color. You can also control focus highlight color using style maps. |
highlightthickness |
Configure this option using styles. This option may not be available for all themes. |
indicatoron |
Not supported. |
justify |
Control how multiple lines are horizontal relative to each other position. Configure this option using a style; the value can be tk.LEFT , tk.CENTER , or tk.RIGHT for left, center, or right alignment respectively Alignment. |
offrelief |
Not supported. |
overrelief |
Use style diagrams to control relief option; see Section 50.2, “TTK Style Map: Dynamic Appearance Changes”. |
padx |
Not supported. |
pady |
Not supported. |
relief |
Use style diagrams to control relief option; see Section 50.2, “TTK Style Map: Dynamic Appearance Changes”. |
selectcolor |
Not supported. |
selectimage |
Not supported. |
state |
atttk There is no option with this name. The state mechanism has been generalized; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
wraplength |
If you are using a style set this option is a certain dimension, then text will be cut into fragments that do not exceed this dimension. |
Methods on ttk include all methods described in Section 46, “Methods common to all ttk widgets” .Checkbutton
, plus:
.invoke()
This method toggles the state of the check button. If there is a command
callback, it will call that callback and return whatever value the callback returns.
The following methods of Tkinter widget Checkbutton
are not supported: .deselect()
, .flash()
, .select()
and .toggle()
. To change the check button’s state through programmatic control, use the .set()
method of the associated control’s variable
.
31. ttk.Combobox
Entry
This widget is a combination of drop-down menu. In your application, you will see the usual text input area with a downward pointing arrow. When the user clicks on the arrow, a drop-down menu appears. If the user clicks on one of these items, that selection replaces the entry’s current contents. However, the user can still type text directly into the entry (when it has focus), or edit the current text.
To create a ttk.Combobox
widget as a child of a given widget
item:parent
w= ttk.Combobox( parent, option= value, ...)
Options:
Table 39. ttk.Combobox
options
class_ |
Widget class name. This can be specified when the widget is created, but cannot be changed later. See Section 27, “Standardized Appearance” for a description of widget classes. |
cursor |
When the mouse is hovering over the check button The cursor that appears; see Section 5.8 “Cursors”. |
exportselection |
By default, if you >EntrySelect text in the widget and it will be automatically exported to the clipboard. To avoid this export, use exportselection=0 . |
height |
Use this option to specify the maximum number of rows displayed in the drop-down menu; the default is 20. If this number of values is exceeded, the drop-down menu will automatically include vertical scroll bars. |
justify |
This option specifies when the text does not completely fill the input How the text will be positioned within the input area. Values can be tk.LEFT left-justified; tk.CENTER to the center; or tk.RIGHT right-justified. |
postcommand |
You can use this option to provide a callback Function that is called when the user clicks the down arrow. This callback may change the values option; if so, the changes will be displayed in the drop-down menu. |
style |
The style used when rendering this check box ;See Section 49, “Using and Customizing ttk Styles”. |
takefocus |
By default, focus traversal will include Attk;.Checkbutton See Section 53, “Focus: Routing Keyboard Input”. To remove a widget from focus traversal, use takefocus=False . |
textvariable |
Control the text displayed in the input area variables; see Section 52, “Control Variables: Values Behind Widgets”. |
validate |
You can use this option to request the widget Dynamic validation of text content. See Section 10.2, “Adding Validation Entries to Widgets”. |
validatecommand |
You can use this option to specify dynamic validation Callback function for the widget’s text content. See Section 10.2, “Adding Validation Entries to Widgets”. |
values |
will appear in the drop-down menu as a sequence of strings options in . |
width |
This option specifies the width of the input area as Number of characters. The actual width will be that number multiplied by the average width of the characters in the valid font. The default value is 20. |
xscrollcommand |
If the widget has an associated horizontal scroll bar , please set this option .set to the method of the scroll bar. |
Methods .Combobox
on ttk include all methods described in Section 46, “Methods common to all ttk widgets”, plus those described in Section 10, “Widgets” All methods on the Tkinter widget, plus: Entry
.current([
index
])
To select an element of an option values
, pass the index of that element as a parameter to this method. If no arguments are provided, the return value is the index values
of the current entry’s text in the list, or -1 values
if the current entry’s text is not in the list.
.set(
value
)
Sets the current text in the widget to
.value
The state of the ttk widget .Combobox
affects its operation. To interrogate or change state, see the .instate()
and .state()
methods in Section 46, “Methods Common to All ttk Widgets”.
-
If a widget is in this
disabled
state, no user actions will change the content. -
If the widget is in the
!disabled
state and is also in thereadonly
state, the user can change the content by using the drop-down menu, but cannot edit the content directly.
https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/ttk-Combobox.html
The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 137627 people are learning the system