wxPython.button.disabled still catching clicks

Aaron Brady castironpi at gmail.com
Tue Dec 23 11:58:26 CET 2008

On Dec 23, 4:50 am, mynthon <mynth... at gmail.com> wrote:
> Hello! (sorry for my english)
> I have a problem with buttons in wxPython. When button is disabled
> (by .Disable() or .Enable(False)) it is grayed out but still receive
> clicks.
> Eg. i have button that disable itself, runs long action and enable
> itself:
> def onClick(self, evt):
>     self.btn.Enable(False)
>     for i in range (1000):
>         print i
>     self.btn.Enable(True)
> when for loop is running button is greyed out and when i click on it
> nothing happens but when loop ends another one is started because
> button "remebered" thad i click on it when was diabled. My only idea
> is to reposition button outside frame instead of disabling it but this
> solution is...not good.
> thanks for any help. Ive searched groups, google and it looks that
> only i have this problem :)

No, it is very common.  During your for loop, the loop is dominating
the process completely.  Events are just building up in the app's
message queue, and don't get handled until after you yield on control.

If you need to run a long task, look into threading, the OnIdle
method, the 'multiprocessing' module, or pump messages during your
long task.

More information about the Python-list mailing list