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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:52:20+00:00 2026-05-15T18:52:20+00:00

Using wxPython, I created a taskbar icon and menu. Everything works fine (in Windows

  • 0

Using wxPython, I created a taskbar icon and menu.
Everything works fine (in Windows at least) upon right-click of the icon: i.e., the menu is displayed, and automatically hidden when you click somewhere else, like on Windows’ taskbar.

Now I do want to have the menu appear when the icon is left-clicked as well.
So I inserted a Bind() to a left-click in the Frame class wrapper, calling the CreatePopupMenu() of the taskbar icon:

import wx
class BibTaskBarIcon(wx.TaskBarIcon):
    def __init__(self, frame):
        wx.TaskBarIcon.__init__(self)
        self.frame = frame
        icon = wx.Icon('test_icon.ico', wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon, "title")

    def CreatePopupMenu(self):
        self.menu = wx.Menu()
        self.menu.Append(wx.NewId(), "dummy menu ")
        self.menu.Append(wx.NewId(), "dummy menu 2")
        return self.menu

class TaskBarFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, style=wx.FRAME_NO_TASKBAR)
        ...
        self.tbicon = BibTaskBarIcon(self)
        wx.EVT_TASKBAR_LEFT_UP(self.tbicon, self.OnTaskBarLeftClick)
        ...

    def OnTaskBarLeftClick(self, evt):
        self.PopupMenu(self.tbicon.CreatePopupMenu())

    ...
def main(argv=None):
    app = wx.App(False)
    TaskBarFrame(None, "testing frame")
    app.MainLoop()

This works fine, except that the menu does not disappear automatically when you click somewhere else on your screen. In fact, left-clicking multiple times on the icon creates multiple menus. The only way to hide the menu(s) is to click on one of its items (which you don’t always want). I’ve looked at the available methods of TaskbarIcon, but I failed to be clear about which one to use to hide the menu (.Destroy() didn’t work). Moreover, I don’t know which event to bind it to (there is a EVT_SET_FOCUS, but I couldn’t find any EVT_LOOSE_FOCUS or similar).

So, how to hide the menu upon losing focus?

EDIT: I’ve inserted a bit more code, to make it more clear

  • 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-15T18:52:20+00:00Added an answer on May 15, 2026 at 6:52 pm

    Ah, I’ve discovered what went wrong. In the statement

    self.PopupMenu(self.tbicon.CreatePopupMenu())
    

    I had bound the popup menu to the frame, instead of to the taskbar icon.

    By changing it to:

    self.tbicon.PopupMenu(self.tbicon.CreatePopupMenu())
    

    all is working well now.

    Thanks for all remarks

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

Sidebar

Related Questions

Using wxPython (I am completely new to it), I have created a taskbar icon
I am building a small app using wxPython.I have created a menu bar ,
I'm using wxPython 2.8 and i'm trying to add scrollbar capabilities on the right
When using wxPython, is it possible to remove or disable the Preferences menu item
I'm coding the menu for an application I'm writing in python, using wxPython libraries
I'm currently using Python 2.7 + wxPython 2.8.11 on my windows machine. While trying
My application is using wxPython and runs on Linux and Windows without modification. The
I'm using wxPython to create a GUI app. Right now I'm using a wx.CheckListBox
I have created a program using python and wxpython. I have created an executable
I have created a GUI program using python and wxpython. It is now ready

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.