diff options
Diffstat (limited to 'Lib/tkinter/__init__.py')
-rw-r--r-- | Lib/tkinter/__init__.py | 139 |
1 files changed, 49 insertions, 90 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 0bccbfc1f5..e54c53f18e 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -1403,6 +1403,48 @@ class CallWrapper: self.widget._report_exception() +class XView: + """Mix-in class for querying and changing the horizontal position + of a widget's window.""" + + def xview(self, *args): + """Query and change the horizontal position of the view.""" + res = self.tk.call(self._w, 'xview', *args) + if not args: + return self._getdoubles(res) + + def xview_moveto(self, fraction): + """Adjusts the view in the window so that FRACTION of the + total width of the canvas is off-screen to the left.""" + self.tk.call(self._w, 'xview', 'moveto', fraction) + + def xview_scroll(self, number, what): + """Shift the x-view according to NUMBER which is measured in "units" + or "pages" (WHAT).""" + self.tk.call(self._w, 'xview', 'scroll', number, what) + + +class YView: + """Mix-in class for querying and changing the vertical position + of a widget's window.""" + + def yview(self, *args): + """Query and change the vertical position of the view.""" + res = self.tk.call(self._w, 'yview', *args) + if not args: + return self._getdoubles(res) + + def yview_moveto(self, fraction): + """Adjusts the view in the window so that FRACTION of the + total height of the canvas is off-screen to the top.""" + self.tk.call(self._w, 'yview', 'moveto', fraction) + + def yview_scroll(self, number, what): + """Shift the y-view according to NUMBER which is measured in + "units" or "pages" (WHAT).""" + self.tk.call(self._w, 'yview', 'scroll', number, what) + + class Wm: """Provides functions for the communication with the window manager.""" @@ -2041,7 +2083,7 @@ def At(x, y=None): else: return '@%r,%r' % (x, y) -class Canvas(Widget): +class Canvas(Widget, XView, YView): """Canvas widget to display graphical elements like lines or text.""" def __init__(self, master=None, cnf={}, **kw): """Construct a canvas widget with the parent MASTER. @@ -2281,30 +2323,6 @@ class Canvas(Widget): def type(self, tagOrId): """Return the type of the item TAGORID.""" return self.tk.call(self._w, 'type', tagOrId) or None - def xview(self, *args): - """Query and change horizontal position of the view.""" - if not args: - return self._getdoubles(self.tk.call(self._w, 'xview')) - self.tk.call((self._w, 'xview') + args) - def xview_moveto(self, fraction): - """Adjusts the view in the window so that FRACTION of the - total width of the canvas is off-screen to the left.""" - self.tk.call(self._w, 'xview', 'moveto', fraction) - def xview_scroll(self, number, what): - """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).""" - self.tk.call(self._w, 'xview', 'scroll', number, what) - def yview(self, *args): - """Query and change vertical position of the view.""" - if not args: - return self._getdoubles(self.tk.call(self._w, 'yview')) - self.tk.call((self._w, 'yview') + args) - def yview_moveto(self, fraction): - """Adjusts the view in the window so that FRACTION of the - total height of the canvas is off-screen to the top.""" - self.tk.call(self._w, 'yview', 'moveto', fraction) - def yview_scroll(self, number, what): - """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT).""" - self.tk.call(self._w, 'yview', 'scroll', number, what) class Checkbutton(Widget): """Checkbutton widget which is either in on- or off-state.""" @@ -2335,7 +2353,7 @@ class Checkbutton(Widget): """Toggle the button.""" self.tk.call(self._w, 'toggle') -class Entry(Widget): +class Entry(Widget, XView): """Entry widget which allows to display simple text.""" def __init__(self, master=None, cnf={}, **kw): """Construct an entry widget with the parent MASTER. @@ -2386,7 +2404,8 @@ class Entry(Widget): self.tk.call(self._w, 'selection', 'from', index) select_from = selection_from def selection_present(self): - """Return whether the widget has the selection.""" + """Return True if there are characters selected in the entry, False + otherwise.""" return self.tk.getboolean( self.tk.call(self._w, 'selection', 'present')) select_present = selection_present @@ -2398,16 +2417,6 @@ class Entry(Widget): """Set the variable end of a selection to INDEX.""" self.tk.call(self._w, 'selection', 'to', index) select_to = selection_to - def xview(self, index): - """Query and change horizontal position of the view.""" - self.tk.call(self._w, 'xview', index) - def xview_moveto(self, fraction): - """Adjust the view in the window so that FRACTION of the - total width of the entry is off-screen to the left.""" - self.tk.call(self._w, 'xview', 'moveto', fraction) - def xview_scroll(self, number, what): - """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).""" - self.tk.call(self._w, 'xview', 'scroll', number, what) class Frame(Widget): """Frame widget which may contain other widgets and can have a 3D border.""" @@ -2449,7 +2458,7 @@ class Label(Widget): """ Widget.__init__(self, master, 'label', cnf, kw) -class Listbox(Widget): +class Listbox(Widget, XView, YView): """Listbox widget which can display a list of strings.""" def __init__(self, master=None, cnf={}, **kw): """Construct a listbox widget with the parent MASTER. @@ -2528,30 +2537,6 @@ class Listbox(Widget): def size(self): """Return the number of elements in the listbox.""" return getint(self.tk.call(self._w, 'size')) - def xview(self, *what): - """Query and change horizontal position of the view.""" - if not what: - return self._getdoubles(self.tk.call(self._w, 'xview')) - self.tk.call((self._w, 'xview') + what) - def xview_moveto(self, fraction): - """Adjust the view in the window so that FRACTION of the - total width of the entry is off-screen to the left.""" - self.tk.call(self._w, 'xview', 'moveto', fraction) - def xview_scroll(self, number, what): - """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT).""" - self.tk.call(self._w, 'xview', 'scroll', number, what) - def yview(self, *what): - """Query and change vertical position of the view.""" - if not what: - return self._getdoubles(self.tk.call(self._w, 'yview')) - self.tk.call((self._w, 'yview') + what) - def yview_moveto(self, fraction): - """Adjust the view in the window so that FRACTION of the - total width of the entry is off-screen to the top.""" - self.tk.call(self._w, 'yview', 'moveto', fraction) - def yview_scroll(self, number, what): - """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT).""" - self.tk.call(self._w, 'yview', 'scroll', number, what) def itemcget(self, index, option): """Return the resource value for an ITEM and an OPTION.""" return self.tk.call( @@ -2798,7 +2783,7 @@ class Scrollbar(Widget): -class Text(Widget): +class Text(Widget, XView, YView): """Text widget which can display text in various forms.""" def __init__(self, master=None, cnf={}, **kw): """Construct a text widget with the parent MASTER. @@ -3120,32 +3105,6 @@ class Text(Widget): """Return all names of embedded windows in this widget.""" return self.tk.splitlist( self.tk.call(self._w, 'window', 'names')) - def xview(self, *what): - """Query and change horizontal position of the view.""" - if not what: - return self._getdoubles(self.tk.call(self._w, 'xview')) - self.tk.call((self._w, 'xview') + what) - def xview_moveto(self, fraction): - """Adjusts the view in the window so that FRACTION of the - total width of the canvas is off-screen to the left.""" - self.tk.call(self._w, 'xview', 'moveto', fraction) - def xview_scroll(self, number, what): - """Shift the x-view according to NUMBER which is measured - in "units" or "pages" (WHAT).""" - self.tk.call(self._w, 'xview', 'scroll', number, what) - def yview(self, *what): - """Query and change vertical position of the view.""" - if not what: - return self._getdoubles(self.tk.call(self._w, 'yview')) - self.tk.call((self._w, 'yview') + what) - def yview_moveto(self, fraction): - """Adjusts the view in the window so that FRACTION of the - total height of the canvas is off-screen to the top.""" - self.tk.call(self._w, 'yview', 'moveto', fraction) - def yview_scroll(self, number, what): - """Shift the y-view according to NUMBER which is measured - in "units" or "pages" (WHAT).""" - self.tk.call(self._w, 'yview', 'scroll', number, what) def yview_pickplace(self, *what): """Obsolete function, use see.""" self.tk.call((self._w, 'yview', '-pickplace') + what) @@ -3331,7 +3290,7 @@ def image_names(): return _default_root.tk.call('image', 'names') def image_types(): return _default_root.tk.call('image', 'types') -class Spinbox(Widget): +class Spinbox(Widget, XView): """spinbox widget.""" def __init__(self, master=None, cnf={}, **kw): """Construct a spinbox widget with the parent MASTER. |