Creating an entry widget

Perhaps the most commonly used widget for collecting information from the end user is the entry widget. The entry widget displays a single-line input area. The widget allows the end user to enter or edit the string within the widget.

The keywords are as follows:

Standard keyword

Interpretation

-background or bg

Specifies the background color to be used when drawing the element.

-borderwidth or -bd

Specifies a non-negative value indicating the width of the 3D border to draw around the outside of the window.

-cursor

Specifies the mouse cursor to be used for the window.

-exportselection

Specifies if a selection within the widget should also be the X selection. This keyword accepts a Boolean value such as true, false, yes, no, 0, or 1.

-font

Specifies the font to use when drawing the element.

-foreground or fg

Specifies the normal foreground color to be used when drawing the element.

-highlightbackground

Specifies the color to display in the traversal highlight region when the window does not have the input focus.

-highlightcolor

Specifies the color to use for the traversal highlight rectangle that is drawn around the window when it has the input focus.

Standard keyword

Interpretation

-highlightthickness

Specifies a non-negative value indicating the width of the highlight rectangle to draw around the outside of the window.

-insertbackground

Specifies the color to be used as the background color in the insertion cursor.

-insertborderwidth

Specifies a non-negative integer value to indicate the width of the 3D border to draw around the insertion cursor.

-insertofftime

Specifies a non-negative integer value to indicate the number of milliseconds the insertion cursor should remain off in each blink cycle. If set to 0 the insertion cursor does not blink.

-insertontime

Specifies a non-negative integer value to indicate the number of milliseconds the insertion cursor should remain on in each blink cycle.

-insertwidth

Specifies the width of the insertion cursor in pixels.

-justify

This keyword is used to specify the justification to apply within the input widget element. Acceptable values are left, center, or right.

-relief

Specifies the 3D effect desired for the window. Acceptable values are raised, sunken, flat, ridge, solid, and groove.

-selectbackground

Specifies the background color to use for selected items.

-selectborderwidth

Specifies the width of the 3D border to draw around selected items.

-selectforeground

Specifies the foreground color to use for selected items.

-takefocus

Determines whether or not the window accepts the focus during keyboard traversal.

-textvariable

Specifies the name of a text variable that contains text to be displayed within an element.

-xscrollcommand

Specifies the command to be called during a scroll event. If this value is not set, no command will be executed.

-height

Specifies the desired height for the window.

-state

Specifies the state of the widget. Acceptable values are normal, active, and disabled.

-width

Specifies the desired width for the window.

How to do it…

In the following example, we will create a label with the text desired. Enter the following command:


1 % entry .e -borderwidth 3 -width 25
.e
2 % pack .e

At this point, your window should look like the following:

How to do it…

How it works…

Based on the keyword and value pairs provided we have created an entry widget named .e with a border width of 3 and a width of 25. Note that the width is based on the space required to display 25 characters of the font specified or the default font and not on screen pixels.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.206.254