OOP __init__ clarification

I’m learning how to implement a Tree object. The code below works but I have a question about the line:

        wx.Frame.__init__(self, parent=None, title='TreeCtrl Demo')

Is this line creating a Frame? The init is confusing me as I’ve not seen that syntax before.

Thank you…

import wx
class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title='TreeCtrl Demo')

        self.tree = wx.TreeCtrl(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize)
        self.root = self.tree.AddRoot('Root ')
        self.tree.AppendItem(self.root, 'Child')
        self.tree.Expand(self.root)
        self.Show()

if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = MainFrame()
    app.MainLoop()

This is a call to the __init__ method of the base class (wx.Frame). Your MainFrame class inherits from wx.Frame.
In python 3 you can use super:
super().__init__(parent=None, title='TreeCtrl Demo')

I see. Thank you for that.

I was also wondering with the file structure having the if name == ‘main’:, when we add other objects to the app such as buttons, labels, trees and toolbars, etc., do these get added above that main line or below it? The reason I ask is that I see code that has def functions declared below that Class block, left flush, so they are are not part of the Class.

in the Python docu there is, like in almost every good product, a section called FAQ and there under

How do I create static class data and static class methods?

is a somewhat comprehensive explanation… :partying_face: