By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,715 Members | 768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,715 IT Pros & Developers. It's quick & easy.

Button Label change on EVT_BUTTON in wxpython!!!

P: 15
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:

Expand|Select|Wrap|Line Numbers
  1. self.run_button=wx.Button(self.panel,ID_RUN_BUTTON,label='Install')
  2. self.Bind(wx.EVT_BUTTON, self.OnRun,id=ID_RUN_BUTTON)
  3.  
  4. def OnRun(self,evt):
  5.     self.run_button.SetLabel('Installing..')
  6.     #call a function that does the installation task
  7.     installation_task()
  8.     #After task completion, set the button label back to "Install"
  9.     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?
Aug 29 '11 #1

✓ answered by dwblas

I don't use wx that much, but wx.Yeild() is the equivalent of Tkinter's update_idletasks. There were some additional problems with the button's definition but that may just be my lack of knowledge on the subject.
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import time
  3.  
  4. class TestWx():
  5.     def __init__(self):
  6.         app=wx.App(False)
  7.         frame=wx.Frame(None, wx.ID_ANY, "TestWx")
  8.         self.panel=wx.Panel(frame)
  9.         self.run_button=wx.Button(self.panel, 1 ,label='Install')
  10.         self.run_button.Bind(wx.EVT_BUTTON, self.OnRun)
  11.  
  12.         frame.Show(True)
  13.         app.MainLoop()
  14.  
  15.     def OnRun(self,evt):
  16.         self.run_button.SetLabel('Installing..')
  17.         wx.Yield()
  18.         time.sleep(2.0)
  19.         #call a function that does the installation task
  20. #        installation_task()
  21.         #After task completion, set the button label back to "Install"
  22.         self.run_button.SetLabel('Install')
  23.         wx.Yield()
  24.  
  25. Tw=TestWx() 

Share this Question
Share on Google+
1 Reply


Expert 100+
P: 621
I don't use wx that much, but wx.Yeild() is the equivalent of Tkinter's update_idletasks. There were some additional problems with the button's definition but that may just be my lack of knowledge on the subject.
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import time
  3.  
  4. class TestWx():
  5.     def __init__(self):
  6.         app=wx.App(False)
  7.         frame=wx.Frame(None, wx.ID_ANY, "TestWx")
  8.         self.panel=wx.Panel(frame)
  9.         self.run_button=wx.Button(self.panel, 1 ,label='Install')
  10.         self.run_button.Bind(wx.EVT_BUTTON, self.OnRun)
  11.  
  12.         frame.Show(True)
  13.         app.MainLoop()
  14.  
  15.     def OnRun(self,evt):
  16.         self.run_button.SetLabel('Installing..')
  17.         wx.Yield()
  18.         time.sleep(2.0)
  19.         #call a function that does the installation task
  20. #        installation_task()
  21.         #After task completion, set the button label back to "Install"
  22.         self.run_button.SetLabel('Install')
  23.         wx.Yield()
  24.  
  25. Tw=TestWx() 
Sep 4 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.