WxPython 2.9 on Windows: button will not Enable()

You are assuming that a change to the state of a GUI element has
happened by the time you get to the next line of code, since GUI
elements are only updated periodically this may not always be the
case, so consider replacing the assert with a if … print … and
see if your expected change of state comes along later.
By using assert you are also assuming that the outcome of the assert
test is SO bad that your user, (in debug mode only), would rather
have a crash than whatever the result of proceeding after the assert
failed but in release mode you don’t care - personally I think that
that is a BAD idea. IMHO In the vast majority of cases when people use an assert they
are making a mistake - they should do one of 4 things:
a) They know about a potential problem so deal with it, (if you
didn’t know that it might be a problem you wouldn’t be able to write
the assert method).
b) If the problem is really a killer it will be in release mode
as well so give some useful output and exit cleanly or
c) If it is a debug build then open the debugger - possibly
breaking at the current line - this will let you find out what is
going on.
d) For wx GUI issues like yours that are basically just a
nuisance try starting InspectionTool, (from wx.lib.inspection, see ),
this will let you look at the state of all your GUI elements.
If all the above doesn’t help try constructing a minimal sample, see
, or better a patch to the appropriate demo that shows the same
behaviour - you will often track down the problem in the process and
if you don’t post it on here - people will then have something to
look at an may be able to help.
Hope the above suggestions are of some help.

···

On 10/02/13 05:17, John Bender wrote:

Hi all,

      One would think this code would always work, given a

reasonable set of assumptions, but it’s failing in my
application:

self.next_button.Enable( self.__next_enabled )

            assert(

self.next_button.Enabled == self.__next_enabled )

http://wiki.wxpython.org/Widget%20Inspection%20Tool

http://wiki.wxpython.org/MakingSampleApps


Steve Gadget Barnes