10.8. Viewports

It is unlikely that you will ever need to use the Viewport widget directly. You are much more likely to use the ScrolledWindow widget *see Section 10.9, “Scrolled Windows”) which in turn uses the Viewport.

A viewport widget allows you to place a larger widget within it such that you can view a part of it at a time. It uses Adjustment object (see Chapter 7, Adjustments) to define the area that is currently in view.

A Viewport is created with the function:

  viewport = gtk.Viewport(hadjustment=None, vadjustment=None)

As you can see you can specify the horizontal and vertical Adjustment objects that the widget is to use when you create the widget. It will create its own if you pass None as the value of the arguments or pass no arguments.

You can get and set the adjustments after the widget has been created using the following four methods:

  viewport.get_hadjustment()

  viewport.get_vadjustment()

  viewport.set_hadjustment(adjustment)

  viewport.set_vadjustment(adjustment)

The only other viewport method is used to alter its appearance:

  viewport.set_shadow_type(type)

Possible values for the type parameter are:

  SHADOW_NONE
  SHADOW_IN
  SHADOW_OUT
  SHADOW_ETCHED_IN
  SHADOW_ETCHED_OUT