6

How can I set the width and height of a GTK Image in Python 3.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
jojemapa
  • 873
  • 2
  • 10
  • 21

1 Answers1

12

First create a GdkPixbuf with the new_from_file_at_scale method which has the following syntax.

new_from_file_at_scale (filename, width, height, preserve_aspect_ratio)

Create the widget Gtk.Image with the method new_from_pixbuf which receives a pixbuf as parameter.

Simple Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf

pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
        filename="1.jpg", 
        width=24, 
        height=24, 
        preserve_aspect_ratio=True)

image = Gtk.Image.new_from_pixbuf(pixbuf)
jojemapa
  • 873
  • 2
  • 10
  • 21