32. ttk.Entry
The purpose of the widget Entry
is to allow the user to enter or edit a single line of text. This is the ttk version of Section 10 “Widgets”. Entry
To create a ttk.Entry
widget as a child of the given widget
item:parent
w = ttk.Entry( parent , option = value , ...)
Options:
Table 40. ttk.Entry
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 |
Appears when the mouse is hovering over a check button cursor; see Section 5.8 “Cursors”. |
exportselection |
By default, if you are in Entry Select text in the widget and it will be automatically exported to the clipboard. To avoid this export, use exportselection=0 . |
font |
Use this option to specify the font for text displayed in the widget; see Section 5.4, “Type Fonts”. For reasons unknown to the author, this option cannot be specified using styles. |
invalidcommand |
You can set this option as a callback function, every This function is called when validation fails (that is, when validatecommand 0 is returned). See Section 10.2, “Adding Validation Entries to Widgets”. |
justify |
This option specifies when text does not completely fill the input area 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. |
show |
To prevent fields such as passwords from being visible on the screen, please Set this option to a string whose first character replaces every actual character in the field. For example, if the field contains “sesame ” but you have specified show='*' , the field will appear as “****** “. |
style |
The style to use when rendering this checkbox; please See Section 49, “Using and Customizing ttk Styles”. |
takefocus |
By default, focus traversal will contain a < em>ttk ;.Checkbutton See Section 53, “Focus: Routing Keyboard Input”. To remove a widget from focus traversal, use takefocus=False . |
textvariable |
Variable that controls the text displayed in the input area ;See Section 52, “Control Variables: Values Behind Widgets”. |
validate |
You can use this option to specify a dynamic validation widget Callback function for text content. See Section 10.2, “Adding Validation Entries to Widgets”. |
validatecommand |
See Section 10.2, “Adding widgets Verify Entry”. |
width |
This option specifies the width of the input area as a 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 scrollbar method. |
The ttk widget constructor does not support these options for the Tkinter Entry
widget: .Entry
Table 41. Tkinter not available in ttkTkinter Entry
option .Entry
background or bg |
background Use style configuration options; see Section 47, “Customizing and Creating ttk Themes and Styles”. bg does not support abbreviations. |
borderwidth or bd |
Use style Configure this option. |
disabledbackground |
Use style image as background option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
disabledforeground |
Use stylemap as foreground option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
foreground or fg |
Use style Configure this option. |
highlightbackground |
To control the focus when the check button has no focus Display color, use stylemaps to control option highlightcolor ; see Section 50.2, “TTK Stylemaps: Dynamic Appearance Changes”. |
highlightcolor |
You can specify this by setting this option in the style 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. |
insertbackground |
Not supported. |
insertborderwidth |
Not supported. |
insertofftime |
Not supported. |
insertontime |
Not supported. |
insertwidth |
Not supported. |
readonlybackground |
Use style diagrams to control background option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
relief |
Configure this option using styles; see Section 47 “Customize and create ttk themes and styles”. |
selectbackground |
Use style diagrams to control background option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
selectborderwidth |
Use style diagrams to control borderwidth code> option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
selectforeground |
Use style diagrams to control foreground option; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
The methods .Entry
on ttk include all methods described in Section 46, “Methods common to all ttk widgets”, and those described in Section 10, “Widgets” All methods on the Tkinter widget.
33. ttk.Frame
Like the Tkinter Frame
widget, the ttk.Frame
widget is a rectangular container for other widgets. To create a Frame
widget as a child of the given widget
:parent
w = ttk.Frame(parent, option = value, ...)
Options include:
Table 42. ttk.Frame
Options
borderwidth |
Use This option specifies the width of the border element; the default value is zero. |
class_ |
You can provide the widget class name when creating this widget. This name can be used to customize the widget’s appearance; see Section 27, “Appearance Standardization”. Once a widget is created, the widget class name cannot be changed. |
cursor |
Use this option to specify the appearance of the mouse cursor when it is over the widget; see Section 5.8, “Cursors”. The default value (empty string) specifies that the cursor is inherited from the parent widget. |
height |
This option is to set the size of the frame height. If you want to force the frame to have a specific height, call .grid_propagate(0) on the widget; see Section 4.2, “Other Grid Management Methods”. |
padding |
To create empty space inside the frame and outside the contained widget, set this option to the desired size. For example, padding='0.5i' will clear a half-inch wide area inside the frame and around the outside of the widget within the frame. |
relief |
Specifies the relief style of the border; see Section 5.6, “Relief Style”. Unless you also increase borderwidth . |
style |
Use this option to specify a custom widget style name; see Section 47, “Customizing and Creating ttk Themes and Styles”. |
takefocus |
Use this option to specify whether a widget is accessed during focus traversal; see Section 53, “Focus: Routing Keyboard Input”. Specify |
width |
This option is to set the size of the frame width. If you want to force the frame to have a specific width, call .grid_propagate(0) on the widget; see Section 4.2, “Other Grid Management Methods”. |
These options on the Tkinter Frame
widget are notavailable as options on the ttk
constructor. Frame:
Table 43. Tkinter Frame
options not available in ttkTkinter
background or bg |
Configure this option using styles; see Section 47, “Customizing and Creating ttk Themes and Styles”. |
highlightbackground |
To control the color of the focus highlight when the frame has no focus, use a style map to control the option highlightcolor ; see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes”. |
highlightcolor |
You can specify the default focus highlight color by setting this option in the style. 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. |
padx |
Not supported. |
pady |
Not supported. |
34. ttk.Label
The purpose of this widget is to display text, images, or both. Usually the content is static, but your program can change the text or images.
To create a ttk.Label
widget as a child of the given widget
item:parent
w= ttk.Label( parent, option= value, ...)
Options include:
Table 44. ttk.Label
Options
anchor |
If If the text and/or images are smaller than the specified width , you can use the anchor option to specify where they should be placed: tk.W , tk.CENTER , or tk.E means left alignment, center alignment or right alignment respectively. You can also specify this option using styles. |
||||||||||||||
background |
Use this option to set the background color. You can also specify this option using styles. | ||||||||||||||
borderwidth |
To add a border around the label, set this option to the width dimension. You can also specify this option using styles. | ||||||||||||||
class_ |
You can provide the widget class name when creating this widget. This name can be used to customize the widget’s appearance; see Section 27, “Appearance Standardization”. Once the widget is created, the widget class name cannot be changed. | ||||||||||||||
compound |
If you provide both the
|
||||||||||||||
cursor |
Use this option to specify the appearance of the mouse cursor when it is over the widget; see Section 5.8, “Cursors”. The default value (empty string) specifies that the cursor is inherited from the parent widget. | ||||||||||||||
font |
Use this option to specify the displayed font text style. You can also specify this option using styles. |
||||||||||||||
foreground |
Use this option to specify the color of text to be displayed. You can also specify this option using styles. |
||||||||||||||
image |
This option specifies one or more images to be displayed in addition to or instead of text. The value must be the image specified in Section 5.9 “Images”. See the You can specify multiple images that will be displayed on a widget based on the widget’s state (see Section 50.2, “TTK Style Maps: Dynamic Appearance Changes” for a discussion of widget states). To do this, provide a tuple as the value of this option, where:
|
||||||||||||||
justify |
If the text you provide contains newline ( '\ ) characters, this option specifies how each line is positioned horizontally: tk.LEFT code>Align left; tk.CENTER to the center; or tk.RIGHT right align each line. You can also specify this option using styles. |
||||||||||||||
padding |
To add more space around all four sides of the text and/or image, set this option to the desired size. You can also specify this option using styles. | ||||||||||||||
relief |
Set this option to Emboss style to create a 3D effect. You need to increase borderwidth for this effect to occur. You can also specify this option using styles. |
||||||||||||||
style |
Use this option to specify a custom widget style name; see Section 47, “Customizing and Creating ttk Themes and Styles”. | ||||||||||||||
takefocus |
Use this option to specify whether the widget is accessed during focus traversal; see Section 53, “Focus: Routing Keyboard Input”. Specify The default value is an empty string; by default, the ttk |
||||||||||||||
text |
The text string to be displayed in the widget. | ||||||||||||||
textvariable |
An instance of StringVar (see Section 52, “Control Variables: Values Behind Widgets”); the text displayed on the widget will be its value. This option is ignored if both text and . textvariabletext |
||||||||||||||
underline |
You can request that a letter in a text string be underlined by setting this option to the position of that letter. For example, the options Using this option does not change any functionality. If you want your application to react to the Q key or some variation (such as control-shift-Q), you need to set up the binding using the event system. |
||||||||||||||
width |
To specify a fixed width, set this option to a number of characters. To specify a minimum width, set this option to minus the number of characters. If this option is not specified, the label area will be large enough to accommodate the current text and/or image. For text displayed in a proportional font, the actual width of the widget will be based on the average width of the characters in the font, rather than a specific number of characters. This option can also be specified via styles. |
||||||||||||||
wraplength |
If you set this option to a certain size, all text will be truncated to lines no longer than this size. This option can also be specified via styles. |
The ttk constructor does not support the following options for the Tkinter version. Label.Label
Table 45. Tkinter not available in ttkTkinter Label
option .Label
activebackground |
Use style diagrams to control background options; see Section 50.2, “TTK Style Map: Dynamic Appearance Changes”. |
activeforeground |
Use style diagrams to control foreground options. |
bitmap |
Not supported. |
disabledforeground |
Use stylemap as foreground option; see Section 50.2, “TTK Style Map: Dynamic Appearance Changes”. |
height |
Not supported. |
highlightbackground |
To control the color of the focus highlight when the label has no focus , use stylemaps to control the option highlightcolor ; see Section 50.2, “TTK Stylemaps: Dynamic Appearance Changes”. |
highlightcolor |
You can specify this by setting this option in the style 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. |
padx |
Not supported. |
pady |
Not supported. |
The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Java Skill TreeHomepageOverview 137655 people are learning the system