Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7616967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:01:17+00:00 2026-05-31T03:01:17+00:00

I have a wxPython application with some code like below. I want to set

  • 0

I have a wxPython application with some code like below. I want to set a value of an attribute of the class MyFrame, but I can’t reference to it.
How can I make this code work?

class MyFrame1(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        self.gauge_1 = wx.Gauge(self, -1)
        self.notebook_1=myNotebook(self, -1)

class myNotebook(wx.Notebook):
    def __init__(self, *args, **kwds):
        wx.Notebook.__init__(self, *args, **kwds)
        self.other_class_1=other_class()
        self.other_class_1.do_sth()

class other_class(object):
    def do_sth(self):
        gauge_1.SetValue(value) #doesn't work of course, how do I do this?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:01:19+00:00Added an answer on May 31, 2026 at 3:01 am

    I think its somewhat poor designer for a child UI element to have specific knowledge about its parent. Its a backwards design. Children should usually have some way of signaling or raising an event and letting the appropriate listener react. But, if this is really want you want to do, then you probably want to get the parent item and act on it directly…

    Note: Don’t do this approach. I’m illustrating why the design has issues…

    First off, you can’t even do it with the way the code is structured, because other_class has no reference to a parent. Its a generic instance. So you would have to do something like…

    class other_class(object):
    
        def __init__(self, parent):
            self.parent = parent
    

    And in your Notebook class…

    class myNotebook(wx.Notebook):
        def __init__(self, *args, **kwds):
            wx.Notebook.__init__(self, *args, **kwds)
            # note here we pass a reference to the myNotebook instance
            self.other_class_1 = other_class(self)
            self.other_class_1.do_sth()
    

    Then once your other_class now knows about its parent, you have to get the parent of the parent to have the MyFrame1 instance…

    class other_class(object):
    
    def __init__(self, parent):
        self.parent = parent
    
    def do_sth(self, value):
        self.parent.GetParent().gauge_1.SetValue(value) 
    

    Do you see now why its a bad design? Multiple levels of objects have to assume knowledge of the parent structure.

    I’m not up on my wxPython so I can’t give you specifics, but here are some possible general approaches to consider:

    1. Determine what the role of other_class really is. If its really meant to operate on children of your MyFrame1, then that functionality belongs under MyFrame1 so it can have knowledge of those members.
    2. If other_class were a wx object, it could emit a wx.Event when the do_sth() method is called. You could bind that event at the MyFrame1 or Notebook level and do whatever work is needed in the handler.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wxPython application that relies on an external config file. I want
I have a application written in wxPython which I want to make multilingual. Our
I have complex GUI application written in Python and wxPython. I want it to
I have a TextCtrl in my wxPython program and I'd like to set its
I have created an application with python and wxpython. I would like to display
I have wxpython application that run over a list of files on some directory
I have a wxPython application I'm bundling into an exe using py2exe. I've defined
I have a wxPython application with the various GUI classes in their own modules
I have wxPython app which is running on MS Windows and I'd like it
I have a wxPython which works perfectly on window xp theme but on switching

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.