0
votes

Suppose I have a tkinter app with the following layout.

Tkinter App Layout

I have used an object-oriented hierarchical model such that the classes are instantiated like this:

MainWindow
├── OptionsFrame
│   ├── DataFrame
│   ├── MetaFrame
│   └── SaveFrame
└── PlotFrame

I want to be able to use the plot button within the SaveFrame to run a function which will plot using a FigureCanvasTkAgg canvas object.

I am struggling to see how I can reach the PlotFrame from within the SaveFrame.

So far I have been using a main parameter in my class declarations, i.e.

class SaveFrame(ttk.Frame):
    def __init__(self, main, *args, **kwargs):
        super().__init__(main, *args, **kwargs)
        self.main = main

which will allow me to go up one level of the hierarchy to the OptionsFrame, but what I need to do is go from

SaveFrame -> OptionsFrame -> MainWindow -> PlotFrame

I don't really know how this is possible.

Thanks

So you've actually described exactly what you need to do. Make sure you have a main attribute for each class (which declares the widget's parent), and you can trace through those to reach MainWindow. After you get to the parent, you should be able to adjust PlotFrame, through the instance that is probably declared in there.Ryan
standard widgets get parent as first argument and they keep it in self.master - so you don't need self.main. And using self.master you can access parent and using self.master.master can acess grandparent - and this can be MainWindow which has access to PlotFramefuras
You should also look into binding button clicksRyan