Hey all, I'm trying to make a panel or frame where widgets can be
added when certain events occur (like when the user presses a button,
etc).
Typing 'wxpython dynamically add widgets' into Google gave some
results on how to do this but none of them worked. It looks like the
window just hangs or stops drawing itself or something
Here is a quick example of what the code might look like. I'm using
Python 2.6.2 on Windows XP
···
#-------------------------------------------------
# Adds a button to the frame every second for 5 seconds
Well its not a problem of "dynamically" - wxPython works in
dynamic manner like that all the time - but a thread-safety problem.
wxPython seems not to be thread-safe to allow .Add()/.Layout()
like this.
When I want to do GUI things comfortably from other threads I put
the function calls like lambda:myAddButton('Button') into a queue
(of funcs) and execute them from the queue from OnIdle/OnTimer -
thus within GUI thread
Robert
knascent wrote:
···
Hey all, I'm trying to make a panel or frame where widgets can be
added when certain events occur (like when the user presses a button,
etc).
Typing 'wxpython dynamically add widgets' into Google gave some
results on how to do this but none of them worked. It looks like the
window just hangs or stops drawing itself or something
Here is a quick example of what the code might look like. I'm using
Python 2.6.2 on Windows XP
#-------------------------------------------------
# Adds a button to the frame every second for 5 seconds
On Aug 1, 3:31 am, Robert <kxrobe...@googlemail.com> wrote:
Well its not a problem of "dynamically" - wxPython works in
dynamic manner like that all the time - but a thread-safety problem.
wxPython seems not to be thread-safe to allow .Add()/.Layout()
like this.
When I want to do GUI things comfortably from other threads I put
the function calls like lambda:myAddButton('Button') into a queue
(of funcs) and execute them from the queue from OnIdle/OnTimer -
thus within GUI thread
Robert
knascent wrote:
> Hey all, I'm trying to make a panel or frame where widgets can be
> added when certain events occur (like when the user presses a button,
> etc).
> Typing 'wxpython dynamically add widgets' into Google gave some
> results on how to do this but none of them worked. It looks like the
> window just hangs or stops drawing itself or something
> Here is a quick example of what the code might look like. I'm using
> Python 2.6.2 on Windows XP
> #-------------------------------------------------
> # Adds a button to the frame every second for 5 seconds
When I want to do GUI things comfortably from other threads I put the function calls like lambda:myAddButton('Button') into a queue (of funcs) and execute them from the queue from OnIdle/OnTimer - thus within GUI thread
wx.CallAfter does essentially the same thing, with no need to maintain and process your own queue. wx.CallLater does it with a timer.