Quick Question regarding Frames

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris S

    #1

    Quick Question regarding Frames

    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

  • Chris S

    #2
    Re: Quick Question regarding Frames

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

    Thanks.

    Chris

    Comment

    • Dave Mandelin

      #3
      Re: Quick Question regarding Frames

      Chris S wrote:[color=blue]
      > 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?[/color]

      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 OnSomethingClic ked(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 UpdateSomeContr ol(self, ...):
      ...

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

      def OnOtherThingCli cked(self, event):
      self.frameA.Upd ateSomeControl( ...)

      --
      Want to play tabletop RPGs over the internet?
      Check out Koboldsoft RPZen: http://www.koboldsoft.com

      Comment

      • Chris S

        #4
        Re: Quick Question regarding Frames

        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

        Comment

        • Dave Mandelin

          #5
          Re: Quick Question regarding Frames

          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()

          --
          Want to play tabletop RPGs over the internet?
          Check out Koboldsoft RPZen: http://www.koboldsoft.com

          Comment

          • Chris Seymour

            #6
            Re: Quick Question regarding Frames

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

            Thanks again.

            Chris

            Comment

            • Dave Mandelin

              #7
              Re: Quick Question regarding Frames

              I'm glad to have helped. Good luck with your project.

              --
              Want to play tabletop RPGs over the internet?
              Check out Koboldsoft RPZen: http://www.koboldsoft.com

              Comment

              Working...