gtk.gdk.Rectangle
Prev | The gtk.gdk Class Reference | Next

## gtk.gdk.Rectangle

gtk.gdk.Rectangle — an object holding data about a rectangle

## Synopsis

    class gtk.gdk.Rectangle(gobject.GBoxed):
        gtk.gdk.Rectangle(x=0, y=0, width=0, height=0)
        def intersect(src)
        def union(src)

## Attributes

"x" | Read-Write | The X coordinate of the top left corner of the rectangle.
"y" | Read-Write | The Y coordinate of the top left corner of the rectangle.
"width" | Read-Write | The width of the rectangle.
"height" | Read-Write | The height of the rectangle.

## Description

A `gtk.gdk.Rectangle` holds the position and size of a rectangle. The position is specified by the "x" and "y" attributes and the size, by the "width" and "height" attributes.

Starting with PyGTK 2.14 `gtk.gdk.Rectangle` objects are properly comparable. By Python rules, rectangles (being mutable) are now unhashable. If you need to use them as dictionary keys, convert rectangle objects to tuples first. You can convert such tuples back to `gtk.gdk.Rectangle` using the following code:

      rectangle = gtk.gdk.Rectangle(*tuple)

Also beginning with PyGTK 2.14 `gtk.gdk.Rectangle` objects have custom support for `repr` Python function. For any rectangle it holds that:

      rectangle == eval(repr(rectangle))

## Constructor

        gtk.gdk.Rectangle(x=0, y=0, width=0, height=0)

`x` : | the X coordinate of the top left corner of the rectangle
`y` : | the Y coordinate of the top left corner of the rectangle
`width` : | the width of the rectangle
`height` : | the height of the rectangle
Returns : | a new `gtk.gdk.Rectangle` object

Creates a new `gtk.gdk.Rectangle` with the attributes specified by `x`, `y`, `width` and `height`. Any unspecified attributes default to 0.

## Methods

### gtk.gdk.Rectangle.intersect

        def intersect(src)

`src` : | a `gtk.gdk.Rectangle` of a 4-tuple specifying the attributes of a rectangle as (x, y, width, height)
Returns : | a `gtk.gdk.Rectangle` that is the intersection of `src` and the rectangle

The `intersect`() method returns a `gtk.gdk.Rectangle` that is the intersection of this rectangle and the `gtk.gdk.Rectangle` specified by `src`. The value of `src` is either a `gtk.gdk.Rectangle` or a 4-tuple containing the position and size of a rectangle. If the rectangles do not intersect the returned `gtk.gdk.Rectangle` will have all attributes set to 0.

### gtk.gdk.Rectangle.union

        def union(src)

`src` : | a `gtk.gdk.Rectangle` of a 4-tuple specifying the attributes of a rectangle as (x, y, width, height)
Returns : | a `gtk.gdk.Rectangle` that includes both `src` and the rectangle

The `union`() method returns a `gtk.gdk.Rectangle` that is the smallest rectangle containing both this rectangle and the `gtk.gdk.Rectangle` specified by `src`. The value of `src` is either a `gtk.gdk.Rectangle` or a 4-tuple containing the position and size of a rectangle.

Prev | Up | Next
gtk.gdk.Pixmap | Home | gtk.gdk.Region