2010-11-30 6 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

다음은 빠르게 해킹 된 것입니다. 우분투 9.10, 파이썬 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

에 테스트되었지만 툴바에 더 많은 버튼이있는 경우이 트릭은 순서를 유지하지 않고 마지막으로 .. 제안을 추가합니까 ?? – DevC

관련 문제