Text widget which can display text in various forms.
| 3618 | |
| 3619 | |
| 3620 | class Text(Widget, XView, YView): |
| 3621 | """Text widget which can display text in various forms.""" |
| 3622 | |
| 3623 | def __init__(self, master=None, cnf={}, **kw): |
| 3624 | """Construct a text widget with the parent MASTER. |
| 3625 | |
| 3626 | STANDARD OPTIONS |
| 3627 | |
| 3628 | background, borderwidth, cursor, |
| 3629 | exportselection, font, foreground, |
| 3630 | highlightbackground, highlightcolor, |
| 3631 | highlightthickness, insertbackground, |
| 3632 | insertborderwidth, insertofftime, |
| 3633 | insertontime, insertwidth, padx, pady, |
| 3634 | relief, selectbackground, |
| 3635 | selectborderwidth, selectforeground, |
| 3636 | setgrid, takefocus, |
| 3637 | xscrollcommand, yscrollcommand, |
| 3638 | |
| 3639 | WIDGET-SPECIFIC OPTIONS |
| 3640 | |
| 3641 | autoseparators, height, maxundo, |
| 3642 | spacing1, spacing2, spacing3, |
| 3643 | state, tabs, undo, width, wrap, |
| 3644 | |
| 3645 | """ |
| 3646 | Widget.__init__(self, master, 'text', cnf, kw) |
| 3647 | |
| 3648 | def bbox(self, index): |
| 3649 | """Return a tuple of (x,y,width,height) which gives the bounding |
| 3650 | box of the visible part of the character at the given index.""" |
| 3651 | return self._getints( |
| 3652 | self.tk.call(self._w, 'bbox', index)) or None |
| 3653 | |
| 3654 | def compare(self, index1, op, index2): |
| 3655 | """Return whether between index INDEX1 and index INDEX2 the |
| 3656 | relation OP is satisfied. OP is one of <, <=, ==, >=, >, or !=.""" |
| 3657 | return self.tk.getboolean(self.tk.call( |
| 3658 | self._w, 'compare', index1, op, index2)) |
| 3659 | |
| 3660 | def count(self, index1, index2, *args): # new in Tk 8.5 |
| 3661 | """Counts the number of relevant things between the two indices. |
| 3662 | If index1 is after index2, the result will be a negative number |
| 3663 | (and this holds for each of the possible options). |
| 3664 | |
| 3665 | The actual items which are counted depends on the options given by |
| 3666 | args. The result is a list of integers, one for the result of each |
| 3667 | counting option given. Valid counting options are "chars", |
| 3668 | "displaychars", "displayindices", "displaylines", "indices", |
| 3669 | "lines", "xpixels" and "ypixels". There is an additional possible |
| 3670 | option "update", which if given then all subsequent options ensure |
| 3671 | that any possible out of date information is recalculated.""" |
| 3672 | args = ['-%s' % arg for arg in args] |
| 3673 | args += [index1, index2] |
| 3674 | res = self.tk.call(self._w, 'count', *args) or None |
| 3675 | if res is not None and len(args) <= 3: |
| 3676 | return (res, ) |
| 3677 | else: |
no outgoing calls