class Tk::Entry

An entry is a widget that displays a one-line text string and allows that string to be edited using widget 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.

Public Class Methods

tk_command() click to toggle source
# File lib/ffi-tk/widget/entry.rb, line 25
def self.tk_command
  'entry'
end

Public Instance Methods

bbox(index) click to toggle source

Returns a list of four numbers describing the bounding box of the character given by index. The first two elements of the list give the x and y coordinates of the upper-left corner of the screen area covered by the character (in pixels relative to the widget) and the last two elements give the width and height of the character, in pixels. The bounding box may refer to a region outside the visible area of the window.

# File lib/ffi-tk/widget/entry.rb, line 58
def bbox(index)
  execute(:bbox, index).to_a(&:to_i)
end
clear() click to toggle source
# File lib/ffi-tk/widget/entry.rb, line 38
def clear
  delete 0, :end
end
cursor() click to toggle source
# File lib/ffi-tk/widget/entry.rb, line 42
def cursor
  index(:insert)
end
cursor=(index) click to toggle source
# File lib/ffi-tk/widget/entry.rb, line 46
def cursor=(index)
  icursor(index)
end
delete(first, last = None) click to toggle source

Delete 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 is not specified it defaults to first+1, i.e. a single character is deleted.

# File lib/ffi-tk/widget/entry.rb, line 67
def delete(first, last = None)
  execute(:delete, first, last)
end
get() click to toggle source

Returns the entry's string.

# File lib/ffi-tk/widget/entry.rb, line 72
def get
  execute(:get).to_s
end
icursor(index) click to toggle source

Arrange for the insertion cursor to be displayed just before the character given by index.

# File lib/ffi-tk/widget/entry.rb, line 78
def icursor(index)
  execute_only(:icursor, index)
end
index(index) click to toggle source

Returns the numerical index corresponding to index.

# File lib/ffi-tk/widget/entry.rb, line 83
def index(index)
  execute(:index, index)
end
insert(index, string) click to toggle source

Insert the characters of string just before the character indicated by index.

# File lib/ffi-tk/widget/entry.rb, line 89
def insert(index, string)
  execute_only(:insert, index, string)
end
scan_dragto(x) click to toggle source

This command computes the difference between its x argument and the x argument to the last scan mark command for the widget. It then adjusts the view left or right by 10 times the difference in x-coordinates. This command is typically associated with mouse motion events in the widget, to produce the effect of dragging the entry at high speed through the window.

# File lib/ffi-tk/widget/entry.rb, line 108
def scan_dragto(x)
  execute_only(:scan, :dragto, x)
end
scan_mark(x) click to toggle source

Records x and the current view in the entry window; used in conjunction with later scan dragto commands. Typically this command is associated with a mouse button press in the widget.

# File lib/ffi-tk/widget/entry.rb, line 97
def scan_mark(x)
  execute_only(:scan, :mark, x)
end
selection_adjust(index) click to toggle source

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 future select to commands. If the selection is not currently in the entry, then a new selection is created to include the characters between index and the most recent selection anchor point, inclusive.

# File lib/ffi-tk/widget/entry.rb, line 120
def selection_adjust(index)
  execute_only(:selection, :adjust, index)
end
selection_clear() click to toggle source

Clear the selection if it is currently in this widget. If the selection is not in this widget then the command has no effect.

# File lib/ffi-tk/widget/entry.rb, line 126
def selection_clear
  execute_only(:selection, :clear)
end
selection_from(index) click to toggle source

Set the selection anchor point to just before the character given by index. Does not change the selection.

# File lib/ffi-tk/widget/entry.rb, line 133
def selection_from(index)
  execute_only(:selection, :from, index)
end
selection_present() click to toggle source

Returns true if there is are characters selected in the entry, false if nothing is selected.

# File lib/ffi-tk/widget/entry.rb, line 139
def selection_present
  execute(:selection, :present) == 1
end
selection_range(from, to) click to toggle source

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.

# File lib/ffi-tk/widget/entry.rb, line 147
def selection_range(from, to)
  execute_only(:selection, :range, from, to)
end
selection_to(index) click to toggle source

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 recent select from or select adjust command in this widget. If the selection is not in this widget then a new selection is created using the most recent anchor point specified for the widget.

# File lib/ffi-tk/widget/entry.rb, line 160
def selection_to(index)
  execute_only(:selection, :to, index)
end
validate() click to toggle source

This command is used to force an evaluation of the validateCommand independent of the conditions specified by the validate option. This is done by temporarily setting the validate option to all. It returns true or false.

# File lib/ffi-tk/widget/entry.rb, line 168
def validate
  execute(:validate) == 1
end
value() click to toggle source
# File lib/ffi-tk/widget/entry.rb, line 29
def value
  get
end
value=(string) click to toggle source
# File lib/ffi-tk/widget/entry.rb, line 33
def value=(string)
  delete 0, :end
  insert 0, string
end
xview(index = None) click to toggle source

Adjusts the view in the window so that the character given by index is displayed at the left edge of the window.

If no index is given, it returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the horizontal span that is visible in the window. For example, if the first element is 0.2 and the second element is 0.6, 20% of the entry's text is off-screen to the left, the middle 40% is visible in the window, and 40% of the text is off-screen to the right. These are the same values passed to scrollbars via the :xscrollcommand option.

# File lib/ffi-tk/widget/entry.rb, line 183
def xview(index = None)
  if index == None
    execute(:xview)
  else
    execute_only(:xview, index)
  end
end
xview_moveto(fraction) click to toggle source

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 between 0 and 1.

# File lib/ffi-tk/widget/entry.rb, line 194
def xview_moveto(fraction)
  execute_only(:xview, :moveto, fraction)
end
xview_scroll(number, what) click to toggle source

This command shifts the view in the window left or right according to number and what. Number must be an integer. What must be either units or pages or an abbreviation of one of these. If what is units, the view adjusts left or right by number average-width characters on the display; if it is pages then the view adjusts by number screenfuls. If number is negative then characters farther to the left become visible; if it is positive then characters farther to the right become visible.

# File lib/ffi-tk/widget/entry.rb, line 207
def xview_scroll(number, what)
  execute_only(:xview, :scroll, number, what)
end