RhetTbull / guitk

Python GUI Toolkit for Tk (guitk): simplify the layout and construction of tkinter graphical user interfaces in python using a declarative syntax.
MIT License
17 stars 1 forks source link

Add Tab() widget for Layout mode #27

Closed RhetTbull closed 1 year ago

RhetTbull commented 1 year ago

with Layout() as layout:
    with Notebook() as nb:
        with Tab("Tab1") as tab1:
            Label("Text here")
            ...
         with Tab("Tab2") as tab2:
            ...

The Tab() widgets would add themselves to the parent Notebook's tabs. If the parent isn't a notebook, raise an error.

RhetTbull commented 1 year ago

Something like this


class Tab(text: str, disabled: bool = False):
    ...

    def add_widget(self, widget: Widget):
        """Add a widget to the tab's layout"""
        self.layout[0].append(widget)

    def __enter__(self):
        self.parent = get_parent()
        if not isinstance(self.parent, guitk.Notebook):
            raise ValueError(...)
        push_parent(self)
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.parent._add_tab(self.layout) # adds the tab to the parent Notebook's self.tabs (this method doesn't currently exist)
        pop_parent()
        return False