title: Python GTK resizing large image to fit inside a window
body: <p><strong>Important note</strong>: I'm using <code>PyGObject</code> to get access to the GTK widgets, not <code>PyGTK</code>. That's what makes this question different from similar ones:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5067310/pygtk-how-do-i-make-an-image-automatically-scale-to-fit-its-parent-widget/5069101">PyGTK: How do I make an image automatically scale to fit it's parent widget?</a></li>
  <li><a href="https://stackoverflow.com/questions/1269320/scale-an-image-in-gtk/1283486">Scale an image in GTK</a></li>
  </ul>
  
  <p>I want to make a very simple app that displays a label, an image and a button, all stacked on top of each other. The app should be running in fullscreen mode.</p>
  
  <p>When I attempted it, I've run into a problem. My image is of very high resolution, so when I simply create it from file and add it, I can barely see 20% of it. </p>
  
  <p>What I want is for this image to be scaled by width according to the size of the window (which is equal to the screen size as the app runs in fullscreen).</p>
  
  <p>I've tried using Pixbufs, but calling <code>scale_simple</code> on them didn't seem to change much.</p>
  
  <p>Here's my current code:</p>
  
  <pre><code>import gi
  gi.require_version('Gtk', '3.0')
  from gi.repository import Gtk, GdkPixbuf
  
  
  class Window(Gtk.Window):
      def __init__(self):
          super().__init__(title='My app')
  
          layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
          dimensions = layout.get_allocation()
  
          pixbuf = GdkPixbuf.Pixbuf.new_from_file('path/to/image')
          pixbuf.scale_simple(dimensions.width, dimensions.height, GdkPixbuf.InterpType.BILINEAR)
          image = Gtk.Image.new_from_pixbuf(pixbuf)
          dismiss_btn = Gtk.Button(label='Button')
  
          dismiss_btn.connect('clicked', Gtk.main_quit)
          layout.add(image)
          layout.add(dismiss_btn)
          self.add(layout)
  
  
  win = Window()
  win.connect("destroy", Gtk.main_quit)
  win.show_all()
  Gtk.main()
  </code></pre>