class Component
Component is an abstract base class representing a visual component of
the graphical user interface. A Component owns a rectangular region
of screen space defined by its bounds property. It may be contained
within another component, in which case it is clipped to the boundaries of
its container.
You should not derive directly from Component. Custom components should be based on View or Frame.
Geometry Properties
The geometry properties control the position and size of the component
within its container. There are several overlapping sets of geometry properties,
corresponding to different ways of defining the component's bounding rectangle.
The properties within each set are orthogonal, meaning that any one of
them may be changed without affecting the others.
- bounds
- A rectangle (left, top, right, bottom) in the container's
coordinate system.
- left
- top
- right
- bottom
- Each of these properties corresponds to one element of the bounds
rectangle. Changing one of these properties changes the position of one
edge of the component without affecting any of the others (and will consequently
change the width or height).
- x
- y
- width
- height
- The x and y properties are the coordinates of the
top left corner of the component in its container's coordinate system.
Assigning to x or y will change the position of the component
within its container, but not its size.
- position
- size
- The position property is equivalent to the tuple (x,
y). The size property is equivalent to the tuple (width, height).
Other Properties
- container
- The Frame which contains this Component, if any. Setting this property
has the effect of removing the Component from the previous container and
adding it to the new container.
- border
- Setting this to true requests that the component be given a border.
The width and style of the border (or whether it even exists at all) is platform-dependent.
When the border is present, it is positioned around the outside of the component's
bounds rectangle, and is not included in the component's size.
Resizing Attributes
These attributes determine what happens to the container's position and
size when the size of its container changes as a result of the user resizing
the containing window, or a containing component's resize method
being called. These attributes are typically not set directly, but are established
by the container's place method when the component is added to
the container.
NOTE: Because these are attributes and not properties, you can't set them using keyword arguments in the constructor.
- hmove
- If true, a change to the width of the container causes this component
to move horizontally by the same amount.
- vmove
- If true, a change to the height of the container causes this component
to move vertically by the same amount.
- hstretch
- If true, a change to the width of the container causes the width
of this component to change by the same amount.
- vstretch
- If true, a change to the height of the container causes the height
of this component to change by the same amount.
Methods
- become_target()
- Arranges for this component to have the first chance to handle
keystrokes, menu commands and other messages dispatched to the containing
window. If the component is not contained in a window, the effect is undefined.
Note: Depending on the
platform, not all components may be capable of becoming targets. This
method is only guaranteed to work on components which directly handle
input events. Its effect on other components is undefined.
- is_target()
- Returns true if this component is the current message target
within its containing window. If the component is not contained in a window,
the result is undefined.
- resize(geometry_property = value,
...)
- Changes the specified geometry properties, and if this causes the
component's size to change, updates the geometries of its subcomponents according
to their resizing attributes. (Assigning directly to the geometry properties
does not cause subcomponents to be moved or resized.)
Destructor
- destroy()
- Destroys the component and removes it from the screen. It should not
be used again.