2 years ago

#56230

test-img

veraf

How to set the title of a taskbaricon in wxpython?

I create a taskbar icon like this:

class TaskBarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
    self.frame = frame
    super(TaskBarIcon, self).__init__()
    self.set_icon(TRAY_ICON)
    self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)

def CreatePopupMenu(self):
    menu = wx.Menu()
    create_menu_item(menu, 'Site', self.on_hello)
    menu.AppendSeparator()
    create_menu_item(menu, 'Exit', self.on_exit)
    return menu

def set_icon(self, path):
    icon = wx.Icon(path)
    self.SetIcon(icon, TRAY_TOOLTIP)

def on_left_down(self, event):      
    print ('Tray icon was left-clicked.')

def on_hello(self, event):
    print ('Hello, world!')

def on_exit(self, event):
    wx.CallAfter(self.Destroy)
    self.frame.Close()

class App(wx.App):
    def OnInit(self):
        frame=wx.Frame(None, title="testit")
        self.SetTopWindow(frame)
        TaskBarIcon(frame) # removing this line changes the window title properly
        return True


app = App(False)
app.MainLoop()

The problem I have is that I want to set the title of the application and later kill the application with taskkill /fi "windowtitle eq testit". If I remove the line TaskBarIcon(frame) this taskkill command works, but it says no tasks matching specified criteria otherwise. How can I change the window title of my application but still create a task bar icon?

Note, this might be possible with something like this, but I prefer to use wxpython over such a low level API.

python

wxpython

win32gui

taskkill

0 Answers

Your Answer

Accepted video resources