2010-11-30 55 views
1

我目前在wxpython中有一个带有开始图标的工具栏。我想要它,所以当这个图标被点击时,它使用的图标和方法变化停止。使用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

下面是一个快速黑客一起。经测试在Ubuntu 9.10,Python的2.6,宽x 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

但在有工具栏上更多的按钮的情况下,这一招不保留订单,并添加到最后..有什么建议? – DevC 2014-04-15 08:18:29

相关问题