@@ -1403,6 +1403,48 @@ def __call__(self, *args):
14031403 self .widget ._report_exception ()
14041404
14051405
1406+ class XView :
1407+ """Mix-in class for querying and changing the horizontal position
1408+ of a widget's window."""
1409+
1410+ def xview (self , * args ):
1411+ """Query and change the horizontal position of the view."""
1412+ res = self .tk .call (self ._w , 'xview' , * args )
1413+ if not args :
1414+ return self ._getdoubles (res )
1415+
1416+ def xview_moveto (self , fraction ):
1417+ """Adjusts the view in the window so that FRACTION of the
1418+ total width of the canvas is off-screen to the left."""
1419+ self .tk .call (self ._w , 'xview' , 'moveto' , fraction )
1420+
1421+ def xview_scroll (self , number , what ):
1422+ """Shift the x-view according to NUMBER which is measured in "units"
1423+ or "pages" (WHAT)."""
1424+ self .tk .call (self ._w , 'xview' , 'scroll' , number , what )
1425+
1426+
1427+ class YView :
1428+ """Mix-in class for querying and changing the vertical position
1429+ of a widget's window."""
1430+
1431+ def yview (self , * args ):
1432+ """Query and change the vertical position of the view."""
1433+ res = self .tk .call (self ._w , 'yview' , * args )
1434+ if not args :
1435+ return self ._getdoubles (res )
1436+
1437+ def yview_moveto (self , fraction ):
1438+ """Adjusts the view in the window so that FRACTION of the
1439+ total height of the canvas is off-screen to the top."""
1440+ self .tk .call (self ._w , 'yview' , 'moveto' , fraction )
1441+
1442+ def yview_scroll (self , number , what ):
1443+ """Shift the y-view according to NUMBER which is measured in
1444+ "units" or "pages" (WHAT)."""
1445+ self .tk .call (self ._w , 'yview' , 'scroll' , number , what )
1446+
1447+
14061448class Wm :
14071449 """Provides functions for the communication with the window manager."""
14081450
@@ -2041,7 +2083,7 @@ def At(x, y=None):
20412083 else :
20422084 return '@%r,%r' % (x , y )
20432085
2044- class Canvas (Widget ):
2086+ class Canvas (Widget , XView , YView ):
20452087 """Canvas widget to display graphical elements like lines or text."""
20462088 def __init__ (self , master = None , cnf = {}, ** kw ):
20472089 """Construct a canvas widget with the parent MASTER.
@@ -2281,30 +2323,6 @@ def select_to(self, tagOrId, index):
22812323 def type (self , tagOrId ):
22822324 """Return the type of the item TAGORID."""
22832325 return self .tk .call (self ._w , 'type' , tagOrId ) or None
2284- def xview (self , * args ):
2285- """Query and change horizontal position of the view."""
2286- if not args :
2287- return self ._getdoubles (self .tk .call (self ._w , 'xview' ))
2288- self .tk .call ((self ._w , 'xview' ) + args )
2289- def xview_moveto (self , fraction ):
2290- """Adjusts the view in the window so that FRACTION of the
2291- total width of the canvas is off-screen to the left."""
2292- self .tk .call (self ._w , 'xview' , 'moveto' , fraction )
2293- def xview_scroll (self , number , what ):
2294- """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2295- self .tk .call (self ._w , 'xview' , 'scroll' , number , what )
2296- def yview (self , * args ):
2297- """Query and change vertical position of the view."""
2298- if not args :
2299- return self ._getdoubles (self .tk .call (self ._w , 'yview' ))
2300- self .tk .call ((self ._w , 'yview' ) + args )
2301- def yview_moveto (self , fraction ):
2302- """Adjusts the view in the window so that FRACTION of the
2303- total height of the canvas is off-screen to the top."""
2304- self .tk .call (self ._w , 'yview' , 'moveto' , fraction )
2305- def yview_scroll (self , number , what ):
2306- """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2307- self .tk .call (self ._w , 'yview' , 'scroll' , number , what )
23082326
23092327class Checkbutton (Widget ):
23102328 """Checkbutton widget which is either in on- or off-state."""
@@ -2335,7 +2353,7 @@ def toggle(self):
23352353 """Toggle the button."""
23362354 self .tk .call (self ._w , 'toggle' )
23372355
2338- class Entry (Widget ):
2356+ class Entry (Widget , XView ):
23392357 """Entry widget which allows to display simple text."""
23402358 def __init__ (self , master = None , cnf = {}, ** kw ):
23412359 """Construct an entry widget with the parent MASTER.
@@ -2386,7 +2404,8 @@ def selection_from(self, index):
23862404 self .tk .call (self ._w , 'selection' , 'from' , index )
23872405 select_from = selection_from
23882406 def selection_present (self ):
2389- """Return whether the widget has the selection."""
2407+ """Return True if there are characters selected in the entry, False
2408+ otherwise."""
23902409 return self .tk .getboolean (
23912410 self .tk .call (self ._w , 'selection' , 'present' ))
23922411 select_present = selection_present
@@ -2398,16 +2417,6 @@ def selection_to(self, index):
23982417 """Set the variable end of a selection to INDEX."""
23992418 self .tk .call (self ._w , 'selection' , 'to' , index )
24002419 select_to = selection_to
2401- def xview (self , index ):
2402- """Query and change horizontal position of the view."""
2403- self .tk .call (self ._w , 'xview' , index )
2404- def xview_moveto (self , fraction ):
2405- """Adjust the view in the window so that FRACTION of the
2406- total width of the entry is off-screen to the left."""
2407- self .tk .call (self ._w , 'xview' , 'moveto' , fraction )
2408- def xview_scroll (self , number , what ):
2409- """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2410- self .tk .call (self ._w , 'xview' , 'scroll' , number , what )
24112420
24122421class Frame (Widget ):
24132422 """Frame widget which may contain other widgets and can have a 3D border."""
@@ -2449,7 +2458,7 @@ def __init__(self, master=None, cnf={}, **kw):
24492458 """
24502459 Widget .__init__ (self , master , 'label' , cnf , kw )
24512460
2452- class Listbox (Widget ):
2461+ class Listbox (Widget , XView , YView ):
24532462 """Listbox widget which can display a list of strings."""
24542463 def __init__ (self , master = None , cnf = {}, ** kw ):
24552464 """Construct a listbox widget with the parent MASTER.
@@ -2528,30 +2537,6 @@ def selection_set(self, first, last=None):
25282537 def size (self ):
25292538 """Return the number of elements in the listbox."""
25302539 return getint (self .tk .call (self ._w , 'size' ))
2531- def xview (self , * what ):
2532- """Query and change horizontal position of the view."""
2533- if not what :
2534- return self ._getdoubles (self .tk .call (self ._w , 'xview' ))
2535- self .tk .call ((self ._w , 'xview' ) + what )
2536- def xview_moveto (self , fraction ):
2537- """Adjust the view in the window so that FRACTION of the
2538- total width of the entry is off-screen to the left."""
2539- self .tk .call (self ._w , 'xview' , 'moveto' , fraction )
2540- def xview_scroll (self , number , what ):
2541- """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2542- self .tk .call (self ._w , 'xview' , 'scroll' , number , what )
2543- def yview (self , * what ):
2544- """Query and change vertical position of the view."""
2545- if not what :
2546- return self ._getdoubles (self .tk .call (self ._w , 'yview' ))
2547- self .tk .call ((self ._w , 'yview' ) + what )
2548- def yview_moveto (self , fraction ):
2549- """Adjust the view in the window so that FRACTION of the
2550- total width of the entry is off-screen to the top."""
2551- self .tk .call (self ._w , 'yview' , 'moveto' , fraction )
2552- def yview_scroll (self , number , what ):
2553- """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
2554- self .tk .call (self ._w , 'yview' , 'scroll' , number , what )
25552540 def itemcget (self , index , option ):
25562541 """Return the resource value for an ITEM and an OPTION."""
25572542 return self .tk .call (
@@ -2798,7 +2783,7 @@ def set(self, *args):
27982783
27992784
28002785
2801- class Text (Widget ):
2786+ class Text (Widget , XView , YView ):
28022787 """Text widget which can display text in various forms."""
28032788 def __init__ (self , master = None , cnf = {}, ** kw ):
28042789 """Construct a text widget with the parent MASTER.
@@ -3120,32 +3105,6 @@ def window_names(self):
31203105 """Return all names of embedded windows in this widget."""
31213106 return self .tk .splitlist (
31223107 self .tk .call (self ._w , 'window' , 'names' ))
3123- def xview (self , * what ):
3124- """Query and change horizontal position of the view."""
3125- if not what :
3126- return self ._getdoubles (self .tk .call (self ._w , 'xview' ))
3127- self .tk .call ((self ._w , 'xview' ) + what )
3128- def xview_moveto (self , fraction ):
3129- """Adjusts the view in the window so that FRACTION of the
3130- total width of the canvas is off-screen to the left."""
3131- self .tk .call (self ._w , 'xview' , 'moveto' , fraction )
3132- def xview_scroll (self , number , what ):
3133- """Shift the x-view according to NUMBER which is measured
3134- in "units" or "pages" (WHAT)."""
3135- self .tk .call (self ._w , 'xview' , 'scroll' , number , what )
3136- def yview (self , * what ):
3137- """Query and change vertical position of the view."""
3138- if not what :
3139- return self ._getdoubles (self .tk .call (self ._w , 'yview' ))
3140- self .tk .call ((self ._w , 'yview' ) + what )
3141- def yview_moveto (self , fraction ):
3142- """Adjusts the view in the window so that FRACTION of the
3143- total height of the canvas is off-screen to the top."""
3144- self .tk .call (self ._w , 'yview' , 'moveto' , fraction )
3145- def yview_scroll (self , number , what ):
3146- """Shift the y-view according to NUMBER which is measured
3147- in "units" or "pages" (WHAT)."""
3148- self .tk .call (self ._w , 'yview' , 'scroll' , number , what )
31493108 def yview_pickplace (self , * what ):
31503109 """Obsolete function, use see."""
31513110 self .tk .call ((self ._w , 'yview' , '-pickplace' ) + what )
@@ -3331,7 +3290,7 @@ def image_names(): return _default_root.tk.call('image', 'names')
33313290def image_types (): return _default_root .tk .call ('image' , 'types' )
33323291
33333292
3334- class Spinbox (Widget ):
3293+ class Spinbox (Widget , XView ):
33353294 """spinbox widget."""
33363295 def __init__ (self , master = None , cnf = {}, ** kw ):
33373296 """Construct a spinbox widget with the parent MASTER.
0 commit comments