Home | Trees | Indices | Help |
|
---|
|
object --+ | CanvasWidget
A collection of graphical elements and bindings used to display a
complex object on a Tkinter Canvas
. A canvas widget is
responsible for managing the Canvas
tags and callback
bindings necessary to display and interact with the object. Canvas
widgets are often organized into hierarchies, where parent canvas widgets
control aspects of their child widgets.
Each canvas widget is bound to a single Canvas
. This
Canvas
is specified as the first argument to the
CanvasWidget
's constructor.
Each canvas widget can support a variety of attributes, which
control how the canvas widget is displayed. Some typical examples
attributes are color
, font
, and
radius
. Each attribute has a default value. This default
value can be overridden in the constructor, using keyword arguments of
the form attribute=value
:
>>> cn = CanvasText(c, 'test', color='red')
Attribute values can also be changed after a canvas widget has been
constructed, using the __setitem__
operator:
>>> cn['font'] = 'times'
The current value of an attribute value can be queried using the
__getitem__
operator:
>>> cn['color'] red
For a list of the attributes supported by a type of canvas widget, see its class documentation.
The attribute 'draggable'
controls whether the user can
drag a canvas widget around the canvas. By default, canvas widgets are
not draggable.
CanvasWidget
provides callback support for two types of
user interaction: clicking and dragging. The method
bind_click
registers a callback function that is called
whenever the canvas widget is clicked. The method
bind_drag
registers a callback function that is called
after the canvas widget is dragged. If the user clicks or drags a
canvas widget with no registered callback function, then the
interaction event will propagate to its parent. For each canvas
widget, only one callback function may be registered for an interaction
event. Callback functions can be deregistered with the
unbind_click
and unbind_drag
methods.
CanvasWidget
is an abstract class. Subclasses are
required to implement the following methods:
__init__
: Builds a new canvas widget. It must perform
the following three tasks (in order):
_add_child_widget
on each child widget.
CanvasWidget
constructor.
_tags
: Returns a list of the canvas tags for all
graphical elements managed by this canvas widget, not including
graphical elements managed by its child widgets.
_manage
: Arranges the child widgets of this canvas
widget. This is typically only called when the canvas widget is
created.
_update
: Update this canvas widget in response to a
change in a single child.
For CanvasWidget
s with no child widgets, the default
definitions for _manage
and _update
may be
used.
If a subclass defines any attributes, then it should implement
__getitem__
and __setitem__
. If either of
these methods is called with an unknown attribute, then they should
propagate the request to CanvasWidget
.
Most subclasses implement a number of additional methods that modify
the CanvasWidget
in some way. These methods must call
parent.update(self)
after making any changes to the canvas
widget's graphical elements. The canvas widget must also call
parent.update(self)
after changing any attribute value
that affects the shape or position of the canvas widget's graphical
elements.
|
|||
|
|||
|
|||
(any) |
|
||
|
|||
|
|||
|
|||
|
|||
string
|
|
||
None
|
|
||
|
|||
|
|||
None
|
|
||
|
|||
list of int
|
|
||
None
|
|
||
4-tuple of int s
|
|
||
|
|||
|
|||
Tkinter.Canvas
|
|
||
list of CanvasWidget
|
|
||
None
|
|
||
int
|
|
||
boolean
|
|
||
None
|
|
||
None
|
|
||
None
|
|
||
|
|||
CanvasWidget or None
|
|
||
None
|
|
||
list of int
|
|
||
|
|||
|
|||
|
|||
int
|
|
||
Inherited from |
|
|||
dictionary
|
__callbacks Registered callbacks. |
||
Tkinter.Canvas
|
__canvas This CanvasWidget 's canvas.
|
||
list of CanvasWidget
|
__children This CanvasWidget 's hierarchical child widgets.
|
||
int
|
__drag_x Where it's been moved to (to find dx) |
||
int
|
__drag_y Where it's been moved to (to find dy) |
||
boolean
|
__draggable Is this canvas widget draggable? |
||
CanvasWidget or None
|
__parent This CanvasWidget 's hierarchical parent widget.
|
||
event
|
__press The ButtonPress event that we're currently handling. |
||
boolean
|
__updating Is this canvas widget currently performing an update? If it is, then it will ignore any new update requests from child widgets. |
|
|||
Inherited from |
|
If this |
If this |
|
Create a new canvas widget. This constructor should only be called by subclass constructors; and it should be called only after the subclass has constructed all graphical canvas objects and registered all child widgets.
|
Handle a motion event:
|
Handle a button-press event:
|
Handle a release callback:
|
repr(x)
|
Set the value of the attribute
|
Begin dragging this object:
|
Register a hierarchical child widget. The child will be considered
part of this canvas widget for purposes of user interaction.
|
Arrange the child widgets of this canvas widget. This method is
called when the canvas widget is initially created. It is also called if
the user calls the
|
Remove a hierarchical child widget. This child will no longer be
considered part of this canvas widget for purposes of user interaction.
|
|
Update this canvas widget in response to a change in one of its children.
|
|
Register a new callback that will be called whenever this
|
Register a new callback that will be called after this
|
|
|
Remove this Note that you only need to destroy a top-level
|
|
|
Move this canvas widget by a given distance. In particular, shift the
canvas widget right by
|
Move this canvas widget to the given location. In particular, shift
the canvas widget such that the corner or side of the bounding box
specified by
|
|
|
Remove a callback that was registered with
|
Update the graphical display of this canvas widget, and all of its ancestors, in response to a change in one of this canvas widget's children.
|
|
|
__callbacksRegistered callbacks. Currently, four keys are used:1 ,
2 , 3 , and 'drag' . The values are
callback functions. Each callback function takes a single argument,
which is the CanvasWidget that triggered the callback.
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Wed Aug 27 15:08:53 2008 | http://epydoc.sourceforge.net |