Entry(3pm)
okay so bestie, this is Entry(3pm) from the User Contributed Perl Documentation, and it's literally all about Tk::Entry. Buckle up, because this widget is iconic and we're gonna get into every detail. π
πΈ NAME πΈ
Tk::Entry β Create and manipulate Entry widgets. That's the whole name, no cap.
β¨ SYNOPSIS β¨
$entry = $parent->Entry(?options?);
π STANDARD OPTIONS π
These are the standard options you can throw at it, bestie. All of them, fr fr:
-background-borderwidth-cursor-exportselection-font-foreground-highlightbackground-highlightcolor-highlightthickness-insertbackground-insertborderwidth-insertofftime-insertontime-insertwidth-justify-relief-selectbackground-selectborderwidth-selectforeground-takefocus-textvariable-xscrollcommand
π WIDGET-SPECIFIC OPTIONS π
Here's where it gets specific, bestie. These are the extra knobs and dials for Entry.
-disabledbackgroundβ Command-Line Name:-disabledbackground; Database Name:disabledBackground; Database Class:DisabledBackground. Specifies the background color to use when the entry is disabled. If this option is the empty string, the normal background color is used.-disabledforegroundβ Command-Line Name:-disabledforeground; Database Name:disabledForeground; Database Class:DisabledForeground. Specifies the foreground color to use when the entry is disabled. If this option is the empty string, the normal foreground color is used.invalidCommandβ Name:invalidCommand; Class:InvalidCommand; Switch:-invalidcommand; Alias:-invcmd. Specifies a script to eval whenvalidateCommandreturns 0. Setting it to<undef>disables this feature (the default). The best use of this option is to set it tobell. See Validation below for more information.-readonlybackgroundβ Command-Line Name:-readonlybackground; Database Name:readonlyBackground; Database Class:ReadonlyBackground. Specifies the background color to use when the entry is read-only. If this option is the empty string, the normal background color is used.showβ Name:show; Class:Show; Switch:-show. If this option is specified, then the true contents of the entry are not displayed in the window. Instead, each character in the entry's value will be displayed as the first character in the value of this option, such as*. This is useful, for example, if the entry is to be used to enter a password. If characters in the entry are selected and copied elsewhere, the information copied will be what is displayed, not the true contents of the entry.stateβ Name:state; Class:State; Switch:-state. Specifies one of three states for the entry:normal,disabled, orreadonly. If the entry isreadonly, then the value may not be changed using widget commands and no insertion cursor will be displayed, even if the input focus is in the widget; the contents of the widget may still be selected. If the entry isdisabled, the value may not be changed, no insertion cursor will be displayed, the contents will not be selectable, and the entry may be displayed in a different color, depending on the values of the-disabledforegroundand-disabledbackgroundoptions.validateβ Name:validate; Class:Validate; Switch:-validate. Specifies the mode in which validation should operate:none,focus,focusin,focusout,key, orall. It defaults tonone. When you want validation, you must explicitly state which mode you wish to use. See Validation below for more.validateCommandβ Name:validateCommand; Class:ValidateCommand; Switch:-validatecommand; Alias:-vcmd. Specifies a script to eval when you want to validate the input into the entry widget. Setting it to"undef"disables this feature (the default). This command must return a valid boolean value. If it returns 0 (or the valid boolean equivalent) then it means you reject the new edition and it will not occur and theinvalidCommandwill be evaluated if it is set. If it returns 1, then the new edition occurs. See Validation below for more information.widthβ Name:width; Class:Width; Switch:-width. Specifies an integer value indicating the desired width of the entry window, in average-size characters of the widget's font. If the value is less than or equal to zero, the widget picks a size just large enough to hold its current text.
π¦ DESCRIPTION π¦
The Entry method creates a new window (given by the $entry argument) and makes it into an entry widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the entry such as its colors, font, and relief. The entry command returns its $entry argument. At the time this command is invoked, there must not exist a window named $entry, but $entry's parent must exist.
An entry is a widget that displays a one-line text string and allows that string to be edited using methods described below, which are typically bound to keystrokes and mouse actions. When first created, an entry's string is empty. A portion of the entry may be selected as described below. If an entry is exporting its selection (see the exportSelection option), then it will observe the standard X11 protocols for handling the selection; entry selections are available as type STRING. Entries also observe the standard Tk rules for dealing with the input focus. When an entry has the input focus it displays an insertion cursor to indicate where new characters will be inserted.
Entries are capable of displaying strings that are too long to fit entirely within the widget's window. In this case, only a portion of the string will be displayed; methods described below may be used to change the view in the window. Entries use the standard xScrollCommand mechanism for interacting with scrollbars (see the description of the -xscrollcommand option for details). They also support scanning, as described below.
π₯ VALIDATION π₯
Validation of entry widgets is derived from part of the patch written by jhobbs@cs.uoregon.edu. This works by setting the validateCommand option to a callback which will be evaluated according to the validate option as follows:
noneβ Default. This means no validation will occur.focusβvalidateCommandwill be called when the entry receives or loses focus.focusinβvalidateCommandwill be called when the entry receives focus.focusoutβvalidateCommandwill be called when the entry loses focus.keyβvalidateCommandwill be called when the entry is edited.allβvalidateCommandwill be called for all above conditions.
The validateCommand and invalidCommand are called with the following arguments:
- The proposed value of the entry. If you are configuring the entry widget to have a new
textvariable, this will be the value of thattextvariable. - The characters to be added (or deleted). This will be
"undef"if validation is due to focus, explcit call to validate or if change is due to"-textvariable"changing. - The current value of entry i.e. before the proposed change.
- index of char string to be added/deleted, if any.
-1otherwise - type of action.
1 == INSERT,0 == DELETE,-1if it's a forced validation or textvariable validation
β οΈ In general, thetextVariableandvalidateCommandcan be dangerous to mix. If you try set thetextVariableto something that thevalidateCommandwill not accept it will be set back to the value of the entry widget. Using thetextVariablefor read-only purposes will never cause problems.
The validateCommand will turn itself off by setting validate to none when an error occurs, for example when the validateCommand or invalidCommand encounters an error in its script while evaluating, or validateCommand does not return a valid boolean value.
With the perl/Tk version validate option is supposed to be "suspended" while executing the validateCommand or the invalidCommand. This is experimental but in theory either callback can "correct" the value of the widget, and override the proposed change. (validateCommand should still return false to inhibit the change from happening when it returns.)
π WIDGET METHODS π
okay bestie so the Entry method is literally the whole reason we're here β it creates a widget object β¨. That object? It supports the configure and cget methods that Tk::options talks about, so you can peek at and tweak all the options we just went over. Oh and also β it inherits every single method from the generic Tk::Widget class, so it's got the whole family's moves π
.
π the index situation (iykyk)
A bunch of the extra methods below take one or more indices as arguments. An index points at a particular character in the entry's string, and you can say it in any of these ways:
numberβ just a plain numerical index, where0is the very first character in the string. classic.anchorβ the anchor point for the selection, which you set with theselectionFromandselectionAdjustmethods. it's giving "where the drama started" π«Άendβ the character just after the last one in the entry's string. it's equivalent to specifying a numerical index equal to the length of the entry's string.insertβ the character adjacent to and immediately following the insertion cursor. πsel.firstβ the first character in the selection. β οΈ it is an error to use this form if the selection isn't in the entry window.sel.lastβ the character just after the last one in the selection. β οΈ also an error to use this form if the selection isn't in the entry window.@numberβ herenumbergets treated as an x-coordinate in the entry's window, and the character spanning that x-coordinate is the one you get. like,@0indicates the left-most character in the window. iconic.
β¨ Abbreviations are totally allowed for any of the forms above, e.g. e or sel.f. And in general, out-of-range indices get automatically rounded to the nearest legal value, so it's forgiving fr fr.
πΈ the additional methods
these are the extra methods entry widgets get. buckle up π
$entry->bbox(index)
Returns a list of four numbers describing the bounding box of the character given by index. First two elements = the x and y coordinates of the upper-left corner of the screen area covered by the character (in pixels, relative to the widget). Last two elements = the width and height of the character, in pixels. Heads up: the bounding box may refer to a region outside the visible area of the window. so don't come for me if it's off-screen π
$entry->cget(?option?)
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the entry command. easy peasy.
$entry->configure(?option?, ?value, option, value, ...?)
Query or modify the configuration options of the widget.
- No option? It returns a list describing all of the available options for
$entry(seeTk::configurefor info on the format of this list). - option with no value? It returns a list describing that one named option β and that list will be identical to the corresponding sublist of the value you'd get if you specified no option at all.
- One or more option-value pairs? Then it modifies the given widget option(s) to have the given value(s), and in this case the command returns an empty string.
Option may have any of the values accepted by the entry command. π
$entry->delete(first, ?last?)
Deletes one or more elements of the entry. First is the index of the first character to delete, and last is the index of the character just after the last one to delete. If last isn't specified it defaults to first+1, i.e. exactly one character gets deleted. Returns an empty string. bye girl π
$entry->get
Returns the entry's string. that's it that's the method π
$entry->icursor(index)
Arranges for the insertion cursor to be displayed just before the character given by index. Returns an empty string.
$entry->index(index)
Returns the numerical index corresponding to index. translation service, unlocked π₯
$entry->insert(index, string)
Inserts the characters of string just before the character indicated by index. Returns an empty string.
$entry->scan(option, args) / $entry->scanOption(args)
This method is used to implement scanning on entries. It has two forms, depending on Option:
$entry->scanMark(x)β Records x and the current view in the entry widget; used in conjunction with laterscanDragtomethods. Typically this method is associated with a mouse button press in the widget. It returns an empty string.$entry->scanDragto(x)β This method computes the difference between its x argument and the x argument to the lastscanMarkmethod for the widget. It then adjusts the view left or right by 10 times the difference in x-coordinates. Typically associated with mouse motion events in the widget, to produce the effect of dragging the entry at high speed through the widget. The return value is an empty string. zoom zoom π¦
$entry->selection(option, arg) / $entry->selectionOption(arg)
This method is used to adjust the selection within an entry. It has several forms, depending on Option:
$entry->selectionAdjust(index)β Locate the end of the selection nearest to the character given by index, and adjust that end of the selection to be at index (i.e. including but not going beyond index). The other end of the selection is made the anchor point for futureselectionTomethods. If the selection isn't currently in the entry, then a new selection is created to include the characters between index and the most recent selection anchor point, inclusive. Returns an empty string.$entry->selectionClearβ Clear the selection if it is currently in this widget. If the selection isn't in this widget then the method has no effect. Returns an empty string.$entry->selectionFrom(index)β Set the selection anchor point to just before the character given by index. Doesn't change the selection. Returns an empty string.$entry->selectionPresentβ Returns1if there are characters selected in the entry,0if nothing is selected. (yes, the original says "if there is are characters selected", and I'm keeping it because it's iconic π)$entry->selectionRange(start, end)β Sets the selection to include the characters starting with the one indexed by start and ending with the one just before end. If end refers to the same character as start or an earlier one, then the entry's selection is cleared. π§Ή$entry->selectionTo(index)β If index is before the anchor point, set the selection to the characters from index up to but not including the anchor point. If index is the same as the anchor point, do nothing. If index is after the anchor point, set the selection to the characters from the anchor point up to but not including index. The anchor point is determined by the most recentselectionFromorselectionAdjustmethod in this widget. If the selection isn't in this widget then a new selection is created using the most recent anchor point specified for the widget. Returns an empty string.
$entry->validate
This command is used to force an evaluation of the validateCommand independent of the conditions specified by the validate option. It returns 0 or 1. main character energy, honestly π
$entry->xview(args)
This command is used to query and change the horizontal position of the text in the widget's window. It can take any of the following forms:
$entry->xviewβ Returns a list containing two elements. Each element is a real fraction between0and1; together they describe the horizontal span that is visible in the window. For example, if the first element is.2and the second element is.7, then 20% of the entry's text is off-screen to the left, the middle 50% is visible in the window, and 30% of the text is off-screen to the right. These are the same values passed to scrollbars via the-xscrollcommandoption. math girlie behavior π$entry->xview(index)β Adjusts the view in the window so that the character given by index is displayed at the left edge of the window.$entry->xviewMoveto(fraction)β Adjusts the view in the window so that the character fraction of the way through the text appears at the left edge of the window. Fraction must be a fraction between0and1.$entry->xviewScroll(number, what)β This method shifts the view in the window left or right according to number and what. Number must be an integer. What must be eitherunitsorpagesor an abbreviation of one of these. If what isunits, the view adjusts left or right by number average-width characters on the display; if it'spagesthen the view adjusts by number screenfuls. If number is negative then characters farther to the left become visible; if it's positive then characters farther to the right become visible. β
β¨ DEFAULT BINDINGS β¨
okay so Tk automatically creates class bindings for entries that give them the following default behavior. In the descriptions below, βwordβ refers to a contiguous group of letters, digits, or _ characters, or any single character other than these. π
[1]β Clickingmouse button 1positions the insertion cursor just before the character underneath the mouse cursor, sets the input focus to this widget, and clears any selection in the widget. Dragging withmouse button 1strokes out a selection between the insertion cursor and the character under the mouse. π±οΈβ¨[2]β Double-clicking withmouse button 1selects the word under the mouse and positions the insertion cursor at the beginning of the word. Dragging after a double click will stroke out a selection consisting of whole words. π―[3]β Triple-clicking withmouse button 1selects all of the text in the entry and positions the insertion cursor before the first character. π―[4]β The ends of the selection can be adjusted by dragging withmouse button 1while theShiftkey is down; this will adjust the end of the selection that was nearest to the mouse cursor whenbutton 1was pressed. If the button is double-clicked before dragging then the selection will be adjusted in units of whole words. π«Ά[5]β Clickingmouse button 1with theControlkey down will position the insertion cursor in the entry without affecting the selection. π[6]β If any normal printing characters are typed in an entry, they are inserted at the point of the insertion cursor. β¨οΈ[7]β The view in the entry can be adjusted by dragging withmouse button 2. Ifmouse button 2is clicked without moving the mouse, the selection is copied into the entry at the position of the mouse cursor. π±οΈ[8]β If the mouse is dragged out of the entry on the left or right sides whilebutton 1is pressed, the entry will automatically scroll to make more text visible (if there is more text off-screen on the side where the mouse left the window). π[9]β TheLeftandRightkeys move the insertion cursor one character to the left or right; they also clear any selection in the entry and set the selection anchor. IfLeftorRightis typed with theShiftkey down, then the insertion cursor moves and the selection is extended to include the new character.Control-LeftandControl-Rightmove the insertion cursor by words, andControl-Shift-LeftandControl-Shift-Rightmove the insertion cursor by words and also extend the selection.Control-bandControl-fbehave the same asLeftandRight, respectively.Meta-bandMeta-fbehave the same asControl-LeftandControl-Right, respectively. π[10]β TheHomekey, orControl-a, will move the insertion cursor to the beginning of the entry and clear any selection in the entry.Shift-Homemoves the insertion cursor to the beginning of the entry and also extends the selection to that point. π[11]β TheEndkey, orControl-e, will move the insertion cursor to the end of the entry and clear any selection in the entry.Shift-Endmoves the cursor to the end and extends the selection to that point. π[12]β TheSelectkey andControl-Spaceset the selection anchor to the position of the insertion cursor. They don't affect the current selection.Shift-SelectandControl-Shift-Spaceadjust the selection to the current position of the insertion cursor, selecting from the anchor to the insertion cursor if there was not any selection previously. π[13]βControl-/selects all the text in the entry. π―[14]βControl-\clears any selection in the entry. π§Ή[15]β TheF16key (labelledCopyon many Sun workstations) orMeta-wcopies the selection in the widget to the clipboard, if there is a selection. π[16]β TheF20key (labelledCuton many Sun workstations) orControl-wcopies the selection in the widget to the clipboard and deletes the selection. If there is no selection in the widget then these keys have no effect. βοΈ[17]β TheF18key (labelledPasteon many Sun workstations) orControl-yinserts the contents of the clipboard at the position of the insertion cursor. π₯[18]β TheDeletekey deletes the selection, if there is one in the entry. If there is no selection, it deletes the character to the right of the insertion cursor. ποΈ[19]β TheBackSpacekey andControl-hdelete the selection, if there is one in the entry. If there is no selection, it deletes the character to the left of the insertion cursor. β¬ οΈ[20]βControl-ddeletes the character to the right of the insertion cursor. β‘οΈ[21]βMeta-ddeletes the word to the right of the insertion cursor. π₯[22]βControl-kdeletes all the characters to the right of the insertion cursor. π[23]βControl-treverses the order of the two characters to the right of the insertion cursor. π
If the entry is disabled using the -state option, then the entry's view can still be adjusted and text in the entry can still be selected, but no insertion cursor will be displayed and no text modifications will take place. π«
The behavior of entries can be changed by defining new bindings for individual widgets or by redefining the class bindings. π οΈ
π KEYWORDS π
entrywidget
This page is from perl v5.40.1, dated 2025-04-13, and it's Entry(3pm) β k bye bestie, go make those entries iconic πβ¨π¦
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms