0

I need to send one variable from one class to other.

My code:

The class I get variable

class Application(tk.Tk):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        #TOOLBAR MENU
        toolbar = tk.Frame(self, bd = 1, relief = tk.RAISED)

        self.choicebutton = tk.Button(toolbar, command=self.choice)

        #TOOLBAR MENU
        toolbar = tk.Frame(self, bd = 1, relief = tk.RAISED)

The class I import variable :

class Frame1(tk.Frame):

    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)
        

        a.Application.choicebutton.config(state="disabled")

I got error:

AttributeError: type object 'Application' has no attribute 'choicebutton'
1
  • You need to use the instance of Application to access choicebutton. Commented Aug 1, 2020 at 12:40

2 Answers 2

1

Assuming parent is the Application object:

class Frame1(tk.Frame):

    def __init__(self, parent, *args, **kwargs):
        super().__init__(parent, *args, **kwargs)

        parent.choicebutton.config(state="disabled")
Sign up to request clarification or add additional context in comments.

Comments

0

change the last line into to

a.Application().choicebutton.config(state="disabled")

3 Comments

Thats' a fix; it's unclear whether creating a new instance of Application is the right thing to do, though. More likely, the instance of Frame is probably supposed to be associated with an existing instance.
What the point of creating a new instance of Application to just setting a checkbutton to disable state because the instance cannot be used later (as it is not assigned to a variable)?
it is just a quick solution without changing much of the code. nothing else. there is no need to create a new instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.