Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8512603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:19:28+00:00 2026-06-11T04:19:28+00:00

Although I have found partial and indirect answers to this question (see, e.g., this

  • 0

Although I have found partial and indirect answers to this question (see, e.g., this link), I am posting this here because putting together the bits and pieces of the puzzle took me a bit of time, and I thought someone else might find my efforts of use.

So, how to achieve a seamless resizing of images on buttons in GTK+ when the parent window is resized?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:19:30+00:00Added an answer on June 11, 2026 at 4:19 am

    The solution offered for PyGTK in the link posted in the question does not work in Python-GI with GTK3, although the trick of using a ScrolledWindow in place of the usual Box was very useful.

    Here is my minimal working solution to getting an image on a button to resize with the container.

    from gi.repository import Gtk, Gdk, GdkPixbuf
    
    class ButtonWindow(Gtk.Window):
    
        def __init__(self):
            Gtk.Window.__init__(self, title="Button Demo")
            self.set_border_width(10)
            self.connect("delete-event", Gtk.main_quit)
            self.connect("check_resize", self.on_check_resize)
    
            self.box = Gtk.ScrolledWindow()
            self.box.set_policy(Gtk.PolicyType.ALWAYS,
                           Gtk.PolicyType.ALWAYS)
            self.add(self.box)
    
            self.click = Gtk.Button()
            self.box.add_with_viewport(self.click)
    
            self.pixbuf = GdkPixbuf.Pixbuf().new_from_file('gtk-logo-rgb.jpg')
            self.image = Gtk.Image().new_from_pixbuf(self.pixbuf)
            self.click.add(self.image)
    
        def resizeImage(self, x, y):
            print('Resizing Image to ('+str(x)+','+str(y)+')....')
            pixbuf = self.pixbuf.scale_simple(x, y,
                                              GdkPixbuf.InterpType.BILINEAR)
            self.image.set_from_pixbuf(pixbuf)
    
        def on_check_resize(self, window):
            print("Checking resize....")
    
            boxAllocation = self.box.get_allocation()
            self.click.set_allocation(boxAllocation)
            self.resizeImage(boxAllocation.width-10,
                             boxAllocation.height-10)
    
    win = ButtonWindow()
    win.show_all()
    Gtk.main()
    

    (The -10 on the width and height are to accommodate the inner borders and padding in the button. I tried fiddling with this to get a bigger image on the button, but the result did not look so nice.)

    The jpeg file used in this example can be downloaded from here.

    I welcome further suggestions on how to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although I have found some solutions to this problem, none of them refer to
Hopefully a simple question although one I have found impossible to answer myself using
I have searched the site and although I have found questions and answers similar
Although I have my php validation doing this, thought I may as well pop
I hope this is a relatively easy problem although I have spent hours websearching
How to create SVN repository on server? Although i have found various articles on
I recently came across the link below which I have found quite interesting. http://en.wikipedia.org/wiki/XOR_linked_list
So, this does not necessarily have to do directly with the code itself, although
I've been struggling with a piece of C# code and although I have found
I have found this popular PHP/MySQL Script called Zip Location by SaniSoft and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.