Изменение метки на панели инструментов с помощью wxPython - PullRequest
1 голос
/ 30 ноября 2010

В настоящее время у меня есть панель инструментов в wxpython со значком запуска.Я хочу, чтобы при щелчке по этому значку значок и метод, в котором он использовал изменения для остановки.

У меня есть такой код:

#!/usr/bin/env python
# encoding: utf-8
"""
logClient2.py    
Created by Allister on 2010-11-30.
"""

import wx
import sqlite3

WINDOW_SIZE = (900,400)

class logClient(wx.Frame):
    def __init__(self, parent, id, title):

        wx.Frame.__init__(self, parent, id, title, size=WINDOW_SIZE)        

        self.toolbar = self.CreateToolBar()
        self.toolbar.AddLabelTool(1, 'Refresh', wx.Bitmap('icons/refresh_icon.png'))
        self.toolbar.Realize()

        self.Bind(wx.EVT_TOOL, self.startLiveUpdate, id=1)

        self.Show(True)

    def startLiveUpdate(self, event):
      pass  


if __name__ == '__main__':
    app = wx.App(False)
    logClient(None, -1, "Log Event Viewer")
    app.MainLoop()

Не совсем уверен, чтоположить в метод startLiveUpdate?

Спасибо за любую помощь!

Ответы [ 2 ]

2 голосов
/ 30 ноября 2010

Вот быстро взломанный вместе. Протестировано на Ubuntu 9.10, Python 2.6, wx 2.8.10.1

#!/usr/bin/env python
# encoding: utf-8
"""
logClient2.py    
Created by Allister on 2010-11-30.
"""

import wx
import sqlite3

WINDOW_SIZE = (900,400)

class logClient(wx.Frame):
    def __init__(self, parent, id, title):

        wx.Frame.__init__(self, parent, id, title, size=WINDOW_SIZE)        

        self.toolbar = self.CreateToolBar()
        self.startLiveUpdate(None)

        self.Show(True)

    def startLiveUpdate(self, event):
        self.createToolbarItem("Refresh", "refresh.jpg", self.stopLiveUpdate)

    def stopLiveUpdate(self, event):
        self.createToolbarItem("Stop", "refresh2.jpg", self.startLiveUpdate)


    def createToolbarItem(self, label, imageName, method):
        self.toolbar.RemoveTool(1)
        self.toolbar.AddLabelTool(1, label, wx.Bitmap(imageName))
        self.toolbar.Realize()
        self.Bind(wx.EVT_TOOL, method, id=1)


if __name__ == '__main__':
    app = wx.App(False)
    logClient(None, -1, "Log Event Viewer")
    app.MainLoop()
0 голосов
/ 30 июля 2018

Вот менее взломанная версия, чем принятый ответ для wxpython 4.x

self.tool = self.toolbar.AddTool(-1, "A tool", "image.png")

...

def change_tool_label(self):
    self.tool.SetLabel("A new label")
    # need to call Realize() to re-draw the toolbar
    self.toolbar.Realize()
...