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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:51:06+00:00 2026-05-18T20:51:06+00:00

I know this is very simple, just use the command self.set_icon_from_file(icon.png) , however my

  • 0

I know this is very simple, just use the command self.set_icon_from_file("icon.png"), however my program still does not display the icon. I made sure the icon.png is in the same working directory as the Python file. I also tried giving the complete file path, but still it does not display the icon.

I am using Ubuntu 10.10 if that helps and using Python V2.6. I use Glade Interface Designer to design the GUI. However, I tried setting the icon both using Glade and using the command above.

I hope I have provided sufficient information.

EDIT: I got the status icon to work in my program.. However in the question I meant the program icon displayed in the task bar and also on the left side of the application bar.

  • 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-18T20:51:07+00:00Added an answer on May 18, 2026 at 8:51 pm

    I made sure the icon.png is in the same working directory of the python file.

    This may be your problem — paths are looked up relative to the working directory of the Python interpreter, not the file containing the code. I often find myself defining a function like:

    def get_resource_path(rel_path):
        dir_of_py_file = os.path.dirname(__file__)
        rel_path_to_resource = os.path.join(dir_of_py_file, rel_path)
        abs_path_to_resource = os.path.abspath(rel_path_to_resource)
        return abs_path_to_resource
    

    Mine isn’t actually quite that verbose, but hopefully the variable names make it clear what’s going on. Also, getting the absolute path isn’t strictly necessary, but might help if you need to debug.

    Then you can just do:

    self.set_icon_from_file(get_resource_path("icon.png"))
    

    Update: Here is a demo program. “icon.png” is in the same directory as this script, and I run it using ./gtktest.py. I see the icon in the top left corner (standard place for my theme). icon.png is just a shape drawn in Inkscape and exported as a bitmap (it works with the original SVG too, anyway).

    #!/usr/bin/env python
    import pygtk
    pygtk.require('2.0')
    import gtk
    
    class HelloWorld:
    
        def delete_event(self, widget, event, data=None):
            return False
    
        def destroy(self, widget, data=None):
            gtk.main_quit()
    
        def __init__(self):
            # create a new window
            self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    
            self.window.set_icon_from_file('icon.png')
    
            self.window.connect("delete_event", self.delete_event)
            self.window.connect("destroy", self.destroy)
    
            # Creates a new button with the label "Hello World".
            self.button = gtk.Button("Hello World")
    
            self.window.add(self.button)
            self.button.show()
            self.window.show()
    
        def main(self):
            gtk.main()
    
    if __name__ == "__main__":
        hello = HelloWorld()
        hello.main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is probably a very simple question but how would I do
This may be very simple question,But please help me. i wanted to know what
I know this might be very easy to some,, I have a simple string
I know it might be a very simple solution for this, but I am
I know this is very basic. I would like to use jQuery to change
Yes, I know this goes against the whole MVC principle! However, I'm just trying
I know this is a very basic question, thats why I just want a
I'm sure my code is correct and this is just something very simple giving
I know this is a very simple question, but I'm having trouble finding the
I have a very weird thing to do and simply don't know how. This

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.