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 5950127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:20:58+00:00 2026-05-22T17:20:58+00:00

The following PyGTK code displays a PNG file in a window. Is there a

  • 0

The following PyGTK code displays a PNG file in a window.

Is there a simpler or better way of displaying the PNG file, like, by using a gtk.DrawingArea? For example, how do you resize the file?

import gtk
import pygtk
pygtk.require('2.0')

class Gui:

    def __init__(self):

        # Create an Image object for a PNG file.
        file_name = "file.png"
        pixbuf = gtk.gdk.pixbuf_new_from_file(file_name)
        pixmap, mask = pixbuf.render_pixmap_and_mask()
        image = gtk.Image()
        image.set_from_pixmap(pixmap, mask)

        # Create a window.
        window = gtk.Window()
        window.set_title("PNG file")
        window.connect("destroy", gtk.main_quit)

        # Show the PNG file in the window.
        window.add(image)
        window.show_all()

if __name__ == "__main__":
    Gui()
    gtk.main()

Acknowledgments: I created the above code using code from other people on the web.

  • 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-05-22T17:20:59+00:00Added an answer on May 22, 2026 at 5:20 pm

    You should call directly image.set_from_file instead of creating a pixbuf and a pixmap. As to handle resizing, I did it once by using directly a gtk.DrawingArea, using the configure signal to get the height and width of the drawing area, and the expose-event event to paint it with cairo on the whole surface. But there may be a way of using a gtk.Image too.

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

Sidebar

Related Questions

I'd like to do the following: Create a fullscreen, always on top pygtk window
Using the Generator class from http://unpythonic.blogspot.com/2007/08/using-threads-in-pygtk.html , the following code makes my program fail:
Following up on my earlier query , is there a way to specify the
Following is the code I'm using in my html with twitter-bootstrap. I am trying
I am not that familiar with PyGTK. Please see the following code. Is it
I'm prototyping GUI layout with PyGTK, sometimes using glade/builder sometimes not, and the following
Following this question: Good crash reporting library in c# Is there any library like
I'm developing an application using python gtk+ and glade. My glade file format is
Following is an onclick method called when a button is clicked. But the code
Following the instructions at MusicalGeometry.com , I've archived and created the .ipa file. However,

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.