Quick Question regarding Frames

C

Chris S

Hello All,
Just starting out with Python and wxPython. I have two Frames, FrameA
and FrameB. FrameA opens FrameB when a button on FrameA is clicked. I
can get this. Now I want a button on FrameB to update a control on
FrameA. I am having an issue with this. Can anyone point me in the
right direction?

Thanks.

Chris
 
C

Chris S

A little further clarification. FrameA and FrameB are in different
modules.

Thanks.

Chris
 
D

Dave Mandelin

Chris said:
Hello All,
Just starting out with Python and wxPython. I have two Frames, FrameA
and FrameB. FrameA opens FrameB when a button on FrameA is clicked. I
can get this. Now I want a button on FrameB to update a control on
FrameA. I am having an issue with this. Can anyone point me in the
right direction?

I'm sure there are many ways of doing it, but I have always done it by
giving FrameB a reference to FrameA. Something like:

class FrameA(wx.Frame):
...
def OnSomethingClicked(self, event):
f = FrameB(self, ...)
f.Show()
event.Skip()

# This function does the updating of the control, to make things
# easier to maintain than having FrameB manipulate controls
# of FrameA directly.
def UpdateSomeControl(self, ...):
...

class FrameB(wx.Frame):
def __init__(self, frameA, ...):
self.frameA = frameA

def OnOtherThingClicked(self, event):
self.frameA.UpdateSomeControl(...)
 
C

Chris S

HI Dave,
Thanks for the reply.
I am a bit confused by this piece of code:
class FrameB(wx.Frame):
def __init__(self, frameA, ...):
self.frameA = frameA

What is frameA in the __init__ definition?
Do I need to create something called frameA in order to pass it to that
__init__ function?

Presently I would call FrameB as
w2 = FrameB(None, -1,"")
w2.Show()

Where would I put the reference to frameA?

Thanks.

Chris
 
D

Dave Mandelin

Hi again. frameA in the __init__ is a parameter that is required to be
the FrameA object that is creating the FrameB. In my example, I was
assuming that the FrameB is created in a method of FrameA, so I created
it passing self as frameA:

w2 = FrameB(self, None, -1,"")
w2.Show()
 
C

Chris Seymour

Hi Dave,
Thanks for taking the time to reply to my posts. It really heped me
understand this better.

Thanks again.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top