PyGTK Containers - PyGTK

What is PyGTK Containers?

PyGTK library offers dissimilar container classes to control the placement of widgets inside a window. The coolest way is to use a fixed container class and place a widget inside it by stating its complete coordinates measured in pixels.

Let us now follow these steps −

Step 1 − Declare an object of the fixed class

Step 2 − Make a button widget and add it to the fixed container by using put() method which needs x and y coordinates. Here, the button will be placed at (100,100) position.

Step 3 − You can place multiple controls in the fixed container. And, add it to the top-level window and invoke the show_all() method

This Absolute Layout, on the other hand, is not suitable because of the resulting reasons −

  • The location of the widget does not change even if the window is resized.
  • The look may not be uniform on different display devices with different resolutions.
  • Modification in the layout is difficult as it may need redesigning of the entire form.

The following is the original window –

hello_world

The following is the resized window −

pygtk_hello_world

The position of the button is unchanged here.

PyGTK API offers container classes for improved management of placing of widgets inside the container. The benefits of Layout managers over absolute positioning are −

  • Widgets inside the window are spontaneously resized.
  • Ensures uniform appearance on display devices with different resolutions.
  • Adding or removing widget dynamically is possible without having to redesign.

gtk.Container acts as the base class for the following classes −

  • gtk.ButtonBox
  • gtk.Box
  • gtk.Alignment
  • gtk.EventBox
  • gtk.Table

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PyGTK Topics