Nest magic-classes¶
Basics¶
Magic classes can be nested. During magic class construction, when a magic class encountered another magic class object, the child object is appended to the parent.
from magicclass import magicclass
@magicclass(layout="horizontal")
class Frame1:
def first_a(self): ...
def first_b(self): ...
@magicclass(layout="horizontal")
class Frame2:
def second_a(self): ...
def second_b(self): ...
def second_c(self): ...
@magicclass
class Main:
frame1 = Frame1()
frame2 = Frame2()
ui = Main()
ui.show()
You can also directly define the child classes inside the parent.
from magicclass import magicclass
@magicclass
class Main:
@magicclass(layout="horizontal")
class Frame1:
def first_a(self): ...
def first_b(self): ...
@magicclass(layout="horizontal")
class Frame2:
def second_a(self): ...
def second_b(self): ...
def second_c(self): ...
ui = Main()
ui.show()

Make Toolbar¶
Similar to menus, magic class also provide a toolbar widget with same API. @magictoolbar
is the
decorator for toolbar.
from magicclass import magicclass, magictoolbar
@magicclass
class Main:
@magictoolbar
class ToolBar:
def a(self): ...
def b(self): ...
def c(self): ...
