473,394 Members | 1,878 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,394 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 3749
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.