473,387 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Button Label change on EVT_BUTTON in wxpython!!!

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() 

1 3748
dwblas
626 Expert 512MB
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

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

Similar topics

2
by: Dot net work | last post by:
Hello. I have an aspx page that changes an HTML label's text using javascript. After the label's text has been changed in this way, I redirect to another aspx page. If I then use the back...
3
by: Roger | last post by:
Is this an easy thing to change? I want to put an option button on a form and want to dynamically change the color (Red, Yellow, Green) for showing a status. I figured it would be an easy task,...
1
by: mail2madhur | last post by:
I need to display different text on label on click of button. <table> <tr> <td> ?????</td> </tr> <tr> <td> <TEXTAREA id="notesId" name="notesdescDisplay" rows=12 cols=83 value=""></TEXTAREA>...
3
by: Paulers | last post by:
Hello, I have an arraylist that looks like this: 1,4,6 I have buttons called button1, button4, button6. I would like to change the text on the buttons that corispond to the numbers in the...
2
by: sathiyamurthy | last post by:
Hi all I need help regarding button colour change in vc++. tell me the steps to implement. also i want to change the button label text size. is there any function for that. Regards sam
0
by: Reagan | last post by:
Alright i did search in google but can't seem to find it so here goes. How do i get a button to change from the default color to 00FF00 when rolled over any suggestions would be appreciated thanks.
3
by: chandan | last post by:
Hi, Is any way to palce a control(button/label) at a location on webPage in runtime?? In page_load envet I am adding a button on the page in the contol collection of a panel but not able to...
2
by: dangerouskicker | last post by:
dear friends any one can guide me or help, How i can change checkbox and radio button color change with java script regards devang
3
by: MLN | last post by:
Hello everyone, I am trying to create a button control with x^y as button label. How to set this text with superscript as label for the button control? Any help in this direction is highly...
5
by: Mahyog | last post by:
Hello everyone, I want to dynamically change location of button, label and panel within the form that can be automatically appear when I restore and maximize the form. Please guys help me. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.