Gtk.AspectFrame
Gtk.AspectFrame — A frame that constrains its child to a particular aspect ratio
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Bin
╰── Gtk.Frame
╰── Gtk.AspectFrame
Functions:
- new
(label:str=None, xalign:float, yalign:float, ratio:float, obey_child:bool) -> Gtk.Widget
- set
(self, xalign:float, yalign:float, ratio:float, obey_child:bool)
Description:
The Gtk.AspectFrame
is useful when you want pack a widget so that it can resize but always retains the same aspect ratio. For instance, one might be drawing a small preview of a larger image. Gtk.AspectFrame
derives from Gtk.Frame, so it can draw a label and a frame around the child. The frame will be shrink-wrapped
to the size of the child.
- Code snap:
frame = Gtk.AspectFrame(label="AspectFrame",
xalign=0.5,
yalign=0.5,
ratio=1,
obey_child=False)
Function Details:
new()
new (label:str=None, xalign:float, yalign:float, ratio:float, obey_child:bool) -> Gtk.Widget
Create a new Gtk.AspectFrame
.
- Returns:
the new
Gtk.AspectFrame
.
set()
set (self, xalign:float, yalign:float, ratio:float, obey_child:bool)
Set parameters for an existing Gtk.AspectFrame
.
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class AspectFrame(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("AspectFrame")
self.set_default_size(200, 200)
self.set_border_width(5)
self.connect("destroy", Gtk.main_quit)
frame = Gtk.AspectFrame(label="AspectFrame",
xalign=0.5,
yalign=0.5,
ratio=1,
obey_child=False)
self.add(frame)
label = Gtk.Label("Label in an AspectFrame")
frame.add(label)
window = AspectFrame()
window.show_all()
Gtk.main()