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 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

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Chances are you're embedding the values directly into your SQL.… May 16, 2026 at 10:09 am
  • Editorial Team
    Editorial Team added an answer You're sharing IP addresses with another site - you'll see… May 16, 2026 at 10:09 am
  • Editorial Team
    Editorial Team added an answer Actual solution is, to escape the token twice. So for… May 16, 2026 at 10:09 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Using wxPython (I am completely new to it), I have created a taskbar icon
I'm using wxPython 2.8 and i'm trying to add scrollbar capabilities on the right
Using SVN you can right click a folder TEST and add it to the
I'm working on a form using wxPython where I want want listctrl's list of
I have a wxpython app designed using XRC which has a multiline textctrl inside
I would like to create an application that has 3-4 frames (or windows) where
I am trying to create a pure-Python application bundle for a wxPython app. I
I am trying create a new frame in wxPython that is a child of
I am creating a menu and assigning images to menu items, sometime first item
Using PHP, I'm trying to give each specific text its own variable. I believe

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.