python

Here is another nifty tidbit of python code that is often hard to find. If you work with Python and wxPython to build gui apps, there are a number of widgets etc., that can be hard to figure out. Adding a task bar icon for your app is one of them. This simple example shows you how to add a taskbar icon, and capture events from it.



import wx

def OnTaskBarRight(event):
             app.ExitMainLoop()
#setup app
app= wx.PySimpleApp()

#setup icon object
icon = wx.Icon("favicon.ico", wx.BITMAP_TYPE_ICO)

#setup taskbar icon
tbicon = wx.TaskBarIcon()
tbicon.SetIcon(icon, "I am an Icon")

#add taskbar icon event
wx.EVT_TASKBAR_RIGHT_UP(tbicon, OnTaskBarRight)

app.MainLoop()

Check out the documentation for wxPython, for more information.

Reblog this post [with Zemanta]
 

7 Responses to “Creating a Task Bar icon in wxPython”

  1. Very nice. thanks man!

  2. Very nice. thanks man!

  3. On linux, this doesnt work, so after digging a little I found documentation of Icon at http://docs.wxwidgets.org/stable/wx_wxbitmapoverview.html , according to information on this page, BITMAP_TYPE_ICO i.e. .ico files are not cross plateform and only work on windows, the only icon type which has full compatability is wxBITMAP_TYPE_XPM i.e. .xpm files, so if we use something like
    icon = wx.Icon(“favicon.xpm”, wx.BITMAP_TYPE_XPM)
    then it will become cross plateform :)

  4. Old post but it works like a charm. I don’t know why Hasani have said the code doesn’t work in linux, because I’m running ubuntu and it works ok.

  5. I’ve been looking everywhere for the simplest way possible to make a task bar icon. A big and fat THANK YOU!

  6. Thanks for the info! And I cannot believe that this topic is somewhat alive even after three years.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2012 techniQal support Suffusion theme by Sayontan Sinha