Button Label change on EVT_BUTTON in wxpython!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • plomon
    New Member
    • Mar 2008
    • 15

    Button Label change on EVT_BUTTON in wxpython!!!

    Some system info before proceeding further:

    Platform: Mac OS X 10.7.1
    Python Version: ActiveState Python 2.7.1
    wxPython Version: wxPython2.9-osx-cocoa-py2.7

    I want the button label to be changed while performing a task

    So, here is what I did/want:

    Code:
    self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install')
    self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON)
    
    def OnRun(self,evt):
    	self.run_button.SetLabel('Installing..')
    	#call a function that does the installation task
    	installation_task()
    	#After task completion, set the button label back to "Install"
    	self.run_button.SetLabel('Install')
    When I try doing this, it doesn't set the label to "Installing " while the task is being performed. Any suggestions how do I achieve this?
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    I don't use wx that much, but wx.Yeild() is the equivalent of Tkinter's update_idletask s. There were some additional problems with the button's definition but that may just be my lack of knowledge on the subject.
    Code:
    import wx
    import time
    
    class TestWx():
        def __init__(self):
            app=wx.App(False)
            frame=wx.Frame(None, wx.ID_ANY, "TestWx")
            self.panel=wx.Panel(frame)
            self.run_button=wx.Button(self.panel, 1 ,label='Install')
            self.run_button.Bind(wx.EVT_BUTTON, self.OnRun)
    
            frame.Show(True)
            app.MainLoop()
         
        def OnRun(self,evt):
            self.run_button.SetLabel('Installing..')
            wx.Yield()
            time.sleep(2.0)
            #call a function that does the installation task
    #        installation_task()
            #After task completion, set the button label back to "Install"
            self.run_button.SetLabel('Install')
            wx.Yield()
    
    Tw=TestWx()

    Comment

    Working...