Search code examples
buttonlabelwxpython

wxPython issue in changing button text


I am working on a wxPython app where I have a button with label text 'Allocate'. Additionally I also have 2 radio options on my app namely 'UnAllocated' and 'Allocated'. When the app launches by default the radio option 'UnAllocated' is selected and the button has label text as 'Allocate'. I have made event driven code to change the label text of the button from 'Allocate' to 'Re-Allocate' upon selecting the radio option 'Allocated'. Uptill now everything is fine and code works as intended.

Now the problem is in the event of radio option 'Allocated' the button label does gets a new label text as 'Re-Allocate' however it is overwriting the previous label text instead of changing. Then as soon as I bring my mouse cursor on the button the text gets refreshed and appears clean and clear. Below is my Code

def rdoAllocated_Click(self, event):
    self.btn_Allocate.SetLabelText('Re-Allocate')

def rdoUnAllocated_Click(self, event):
    self.btn_Allocate.SetLabelText('Allocate')

is there a way of refreshing the button label text automatically after the change to display clearly the new text instead of unreadable overwritten text. Here is the image how it looks when getting updated


Solution

  • Try calling self.btn_Allocate.Refresh() This can happen sometimes, depending on platform and widget types. The Refresh simply tells the system to send a paint event in the near future, and will most-likely take care of the problem for you. If not then you may need to call the parent window's Refresh instead.