class Main(tk.Frame): def __init__(self, root): super().__init__(root) self.init_main() def update(self): conn, cursor = BD().connect() cursor.execute('SELECT * FROM albums') for row in cursor.fetchall(): self.tree.insert('', tk.END, values=row) conn.commit() conn.close() self.tree.pack() class Child(tk.Toplevel): def __init__(self): super().__init__(root) self.init_child() def validation_of_entered_data(self, entry_description, combobox, entry_money): BD().add_item(description, combobox, entry_money) Main().update() 

I need to execute the update function from another class, I tried to do it like this

 Main().update() 

But an error occurred, as I understand it, you need to pass some kind of argument, but I don’t know which one. Tell me what I need to do to correct the error?

    1 answer 1

    Your update is not a class method, but an instance method. Accordingly, it is impossible to simply call it from a class, you first need to create (or take an already existing) copy of the Main class.

    From the description of the __init__ method of the Main class, it is obvious that to create it, you must pass the root argument.

    • Thanks for the help! Could you give me an example of the code, I do not quite understand how I can do all this? - Aleksei Grabor
    • one
      From the code snippet you provide, you cannot say anything definite. Most likely, somewhere outside of these classes, Main (root) should be called only once, and the object created as a result of this should be somehow transferred to Child. And inside Child there should be work already with this existing object, and not to call again Main (). - Xander
    • Thanks, it helped! - Aleksei Grabor