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

  • Home
  • SEARCH
  • 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 8002363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:20:20+00:00 2026-06-04T16:20:20+00:00

Now I made WidgetArea originally for Windows, but being primarily a Linux user. I

  • 0

Now I made WidgetArea originally for Windows, but being primarily a Linux user. I wanted to make it for Linux as well, but mainly to learn more about the file dialog in PyGTK. So I took a look at this tutorial to have a better understanding of it, while working on this simple, yet small application, as that’s easier for me to learn, and understand by experimentation.

So here’s my source code.

#!/usr/bin/env python

import sys, os
import pygtk, gtk, gobject
import pygst
pygst.require("0.10")
import gst

class WidgetArea(gtk.Window):

   def addwidget(self, w):
    self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.win.set_title("Widget")
    self.win.set_decorated(False)
    self.win.set_has_frame(False)
    self.win.set_resizable(False)
    self.win.set_keep_above(True)
    self.win.set_property('skip-taskbar-hint', True)
    self.previewimage = gtk.Image()
    self.win.add(self.previewimage)
    self.win.show_all()

   def pinning(self, checkbox):
    if checkbox.get_active():
     self.set_keep_above(True)
    else:
     self.set_keep_above(False)

   def change_size(self, w):
     width = int(self.entryw.get_text())
     height = int(self.entryh.get_text())
     self.win.set_size_request(width,height)

   def __init__(self):
    super(WidgetArea, self).__init__()
    self.set_position(gtk.WIN_POS_CENTER)
    self.set_title("WidgetArea")
    self.set_resizable(False)
    self.set_keep_above(True)
    self.set_property('skip-taskbar-hint', True)
    self.connect("destroy", gtk.main_quit, "WM destroy")
    vbox = gtk.VBox(spacing=0)
    hbox = gtk.HBox(spacing=0)
    hbox2 = gtk.HBox(spacing=0)
    hbox3 = gtk.HBox(spacing=0)
    hbox4 = gtk.HBox(spacing=0)

    self.widgetsize = gtk.Label("Widget Size:")
    self.widgetsize.set_size_request(100, 30)

    self.entryw = gtk.Entry()
    self.entryh = gtk.Entry()
    self.entryw.set_text("270")
    self.entryw.set_size_request(75, 30)
    labelcoma = gtk.Label(",")
    labelcoma.set_size_request(10, 30)
    self.entryh.set_text("221")
    self.entryh.set_size_request(75, 30)
    labelspac1 = gtk.Label(" ")
    labelspac1.set_size_request(10, 30)
    hbox.pack_start(self.widgetsize)
    hbox.pack_start(self.entryw)
    hbox.pack_start(labelcoma)
    hbox.pack_start(self.entryh)
    hbox.pack_start(labelspac1, 0, 0, 10)

    check = gtk.CheckButton("Pin This Window")
    check.set_active(True)
    check.connect("clicked", self.pinning)
    hbox.pack_start(check, 0, 0, 10)

    labelspac2 = gtk.Label(" ")
    labelspac2.set_size_request(250, 15)
    hbox2.pack_start(labelspac2)

    filefilter = gtk.FileFilter()
    filefilter.set_name("Images")
    filefilter.add_mime_type("image/png")
    filefilter.add_mime_type("image/jpeg")
    filefilter.add_mime_type("image/gif")
    filefilter.add_mime_type("image/tiff")
    filefilter.add_mime_type("image/svg+xml")
    filefilter.add_pattern("*.jpg")

    self.ref_file_button = gtk.FileChooserButton('Add Widget')
    self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))
    self.ref_file_button.set_filter(filefilter)
    self.ref_file_button.connect("file-set", self.on_open_clicked)
    hbox3.pack_start(self.ref_file_button, 150, 150, 10)

    labelspac5 = gtk.Label(" ")
    labelspac5.set_size_request(0, 10)
    hbox4.pack_start(labelspac5)

    vbox.pack_start(hbox)
    vbox.pack_start(hbox2)
    vbox.pack_start(hbox3)
    vbox.pack_start(hbox4)
    self.add(vbox)
    self.show_all()

   def on_open_clicked(self, widget, data=None):
    ref_image_path = widget.get_filename()
    self.previewimage.set_from_file(ref_image_path)
    self.addwidg.connect("clicked", self.addwidget)
    self.addwidg.connect("clicked", self.change_size)
    ref_image_path.destroy()

WidgetArea()
gtk.gdk.threads_init()
gtk.main()

I removed the following code (1st), due to the following error (2nd).

self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))

Traceback (most recent call last):
  File "./widgetarea.py", line 109, in <module>
    WidgetArea()
  File "./widgetarea.py", line 86, in __init__
    self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"]))
AttributeError: 'WidgetArea' object has no attribute 'rootdir'

Now this isn’t a big deal at this point. My main goal is to get the image displayed in a new window. So after I removed the code above, due to that error I got another one.

Traceback (most recent call last):
  File "./widgetarea.py", line 103, in on_open_clicked
    self.previewimage.set_from_file(ref_image_path)
AttributeError: 'WidgetArea' object has no attribute 'previewimage'

All I’m having problems with is when you browse to select an image I want the chosen image, when pressed OK to launch as a new window displaying the chosen image in that window, as stated above.

  • 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-04T16:20:22+00:00Added an answer on June 4, 2026 at 4:20 pm

    I have used something like this in one of my projects. And it’s working well for me in Linux.

    def __init__(self):
        # Define all the widgets   
        image_filter = gtk.FileFilter()
        image_filter.set_name("Images")
        image_filter.add_mime_type("image/png")
        image_filter.add_mime_type("image/jpeg")
        image_filter.add_mime_type("image/gif")
        image_filter.add_mime_type("image/tiff")
        image_filter.add_mime_type("image/svg+xml")
        image_filter.add_pattern("*.jpg")
    
        self.ref_file_button = gtk.FileChooserButton('Select Image')
        self.ref_file_button.set_size_request(100,30)
        self.ref_file_button.set_current_folder("/".join([self.rootdir,"pics"])) # set directory path
        self.ref_file_button.set_filter(image_filter)
        self.ref_file_button.set_tooltip_text('Select Image')
        self.ref_file_button.connect("file-set", self.ref_image_selected)
    
    def ref_image_selected(self,widget,data=None):
        ref_image_path = widget.get_filename()
        print ref_image_path
    

    After getting the path of the image, you can load it using gtk.Image

    EDIT:

    Your code is a bit erroneous. You are never calling the function addwidget(), and hence self.previewimage is not defined. and so it gives AttributeError.

    def __init__(self):
        # your code
        self.add(vbox)
        self.addwidget(200)   # I don't know what 'w' is. so I took a random number.
        self.show_all()
    
    def  on_open_clicked(self, widget, data=None):
        ref_image_path = widget.get_filename()
        self.previewimage.set_from_file(ref_image_path)
        self.addwidg.connect("clicked", self.addwidget)
        self.addwidg.connect("clicked", self.change_size)
        ref_image_path.destroy()
    

    What is self.addwidg ?

    And I am able to view the image now.

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

Sidebar

Related Questions

I made a demo using v2, and now I want to use v3. But
I made a similar question a few days ago, but now I have new
I've now made a JList which is based on an arraylist, and is being
I wrote a windows service and installed it. Now I made a few changes
now i made JavaScript code (jquery code) and when i click ok it return
I have made a data model, and now I've made a 2nd version. All
My apps are installed. They used to work. Now that I made some edits
i made news applicaion in android using RSS feed and now i want to
I made query that accepts two parameters. Now I want to use that query
I made an MFC application, and now i want to turn off the window's

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.