We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add a `clear()` method to remove all children
### What is the problem or limitation you are having?

At present, you can:
* add a single child to a widget (`widget.add(child)`)
* remove a single child to a widget (`widget.remove(child)`)
* add multiple children to a widget in a single call (`widget.add(child1, child2)`)
* Remove multiple children from a widget in a single call  (`widget.remove(child1, child2)`)

However, there is no API to remove *all* children from a node.


### Describe the solution you'd like

`widget.clear()` should remove all children from a widget. As of Travertino 0.2.0, a `clear()` API exists; however, invoking it could have unexpected consequences, as it doesn't include the Toga-side cleanups implied by this change.

### Describe alternatives you've considered

`widget.remove(*widget.children)` is a workaround at present, but isn't a great API.

### Additional context

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `core/src/toga/widgets/base.py`
Content:
```
1 from builtins import id as identifier
2 
3 from travertino.node import Node
4 
5 from toga.platform import get_platform_factory
6 from toga.style import Pack, TogaApplicator
7 
8 
9 class WidgetRegistry(dict):
10     # WidgetRegistry is implemented as a subclass of dict, because it provides
11     # a mapping from ID to widget. However, it exposes a set-like API; add()
12     # and update() take instances to be added, and iteration is over values.
13 
14     def __init__(self, *args, **kwargs):
15         super().__init__(*args, **kwargs)
16 
17     def __setitem__(self, key, value):
18         # We do not want to allow setting items directly but to use the "add"
19         # method instead.
20         raise RuntimeError("Widgets cannot be directly added to a registry")
21 
22     def update(self, widgets):
23         for widget in widgets:
24             self.add(widget)
25 
26     def add(self, widget):
27         if widget.id in self:
28             # Prevent from adding the same widget twice
29             # or adding 2 widgets with the same id
30             raise KeyError(f"There is already a widget with the id {widget.id!r}")
31         super().__setitem__(widget.id, widget)
32 
33     def remove(self, id):
34         del self[id]
35 
36     def __iter__(self):
37         return iter(self.values())
38 
39 
40 class Widget(Node):
41     _MIN_WIDTH = 100
42     _MIN_HEIGHT = 100
43 
44     def __init__(
45         self,
46         id=None,
47         style=None,
48     ):
49         """Create a base Toga widget.
50 
51         This is an abstract base class; it cannot be instantiated.
52 
53         :param id: The ID for the widget.
54         :param style: A style object. If no style is provided, a default style
55             will be applied to the widget.
56         """
57         super().__init__(
58             style=style if style else Pack(),
59             applicator=TogaApplicator(self),
60         )
61 
62         self._id = str(id) if id else str(identifier(self))
63         self._window = None
64         self._app = None
65         self._impl = None
66 
67         self.factory = get_platform_factory()
68 
69     def __repr__(self):
70         return f"<{self.__class__.__name__}:0x{identifier(self):x}>"
71 
72     @property
73     def id(self):
74         """The unique identifier for the widget."""
75         return self._id
76 
77     @property
78     def tab_index(self):
79         """The position of the widget in the focus chain for the window.
80 
81         .. note::
82 
83             This is a beta feature. The ``tab_index`` API may change in
84             future.
85         """
86         return self._impl.get_tab_index()
87 
88     @tab_index.setter
89     def tab_index(self, tab_index):
90         self._impl.set_tab_index(tab_index)
91 
92     def add(self, *children):
93         """Add the provided widgets as children of this widget.
94 
95         If a child widget already has a parent, it will be re-parented as a
96         child of this widget. If the child widget is already a child of this
97         widget, there is no change.
98 
99         Raises ``ValueError`` if this widget cannot have children.
100 
101         :param children: The widgets to add as children of this widget.
102         """
103         for child in children:
104             if child.parent is not self:
105                 # remove from old parent
106                 if child.parent:
107                     child.parent.remove(child)
108 
109                 # add to new parent
110                 super().add(child)
111 
112                 # set app and window
113                 child.app = self.app
114                 child.window = self.window
115 
116                 self._impl.add_child(child._impl)
117 
118         if self.window:
119             self.window.content.refresh()
120 
121     def insert(self, index, child):
122         """Insert a widget as a child of this widget.
123 
124         If a child widget already has a parent, it will be re-parented as a
125         child of this widget. If the child widget is already a child of this
126         widget, there is no change.
127 
128         Raises ``ValueError`` if this node cannot have children.
129 
130         :param index: The position in the list of children where the new widget
131             should be added.
132         :param child: The child to insert as a child of this node.
133         """
134         if child.parent is not self:
135             # remove from old parent
136             if child.parent:
137                 child.parent.remove(child)
138 
139             # add to new parent
140             super().insert(index, child)
141 
142             # set app and window
143             child.app = self.app
144             child.window = self.window
145 
146             self._impl.insert_child(index, child._impl)
147 
148         if self.window:
149             self.window.content.refresh()
150 
151     def remove(self, *children):
152         """Remove the provided widgets as children of this node.
153 
154         Any nominated child widget that is not a child of this widget will
155         not have any change in parentage.
156 
157         Raises ``ValueError`` if this widget cannot have children.
158 
159         :param children: The child nodes to remove.
160         """
161         for child in children:
162             if child.parent is self:
163                 super().remove(child)
164 
165                 child.app = None
166                 child.window = None
167 
168                 self._impl.remove_child(child._impl)
169 
170         if self.window:
171             self.window.content.refresh()
172 
173     @property
174     def app(self):
175         """The App to which this widget belongs.
176 
177         When setting the app for a widget, all children of this widget will be
178         recursively assigned to the same app.
179 
180         Raises ``ValueError`` if the widget is already associated with another
181         app.
182         """
183         return self._app
184 
185     @app.setter
186     def app(self, app):
187         # If the widget is already assigned to an app
188         if self._app:
189             if self._app == app:
190                 # If app is the same as the previous app, return
191                 return
192 
193             # Deregister the widget from the old app
194             self._app.widgets.remove(self.id)
195 
196         self._app = app
197         self._impl.set_app(app)
198         for child in self.children:
199             child.app = app
200 
201         if app is not None:
202             # Add this widget to the application widget registry
203             app.widgets.add(self)
204 
205     @property
206     def window(self):
207         """The window to which this widget belongs.
208 
209         When setting the window for a widget, all children of this widget will be
210         recursively assigned to the same window.
211         """
212         return self._window
213 
214     @window.setter
215     def window(self, window):
216         # Remove the widget from the widget registry it is currently a part of
217         if self.window is not None:
218             self.window.widgets.remove(self.id)
219 
220         self._window = window
221         self._impl.set_window(window)
222 
223         for child in self.children:
224             child.window = window
225 
226         if window is not None:
227             # Add this widget to the window's widget registry
228             window.widgets.add(self)
229 
230     @property
231     def enabled(self):
232         """Is the widget currently enabled? i.e., can the user interact with the widget?"""
233         return self._impl.get_enabled()
234 
235     @enabled.setter
236     def enabled(self, value):
237         self._impl.set_enabled(bool(value))
238 
239     def refresh(self):
240         self._impl.refresh()
241 
242         # Refresh the layout
243         if self._root:
244             # We're not the root of the node heirarchy;
245             # defer the refresh call to the root node.
246             self._root.refresh()
247         else:
248             self.refresh_sublayouts()
249             # We can't compute a layout until we have a viewport
250             if self._impl.viewport:
251                 super().refresh(self._impl.viewport)
252 
253     def refresh_sublayouts(self):
254         for child in self.children:
255             child.refresh_sublayouts()
256 
257     def focus(self):
258         """Give this widget the input focus.
259 
260         This method is a no-op if the widget can't accept focus. The ability of a widget
261         to accept focus is platform-dependent. In general, on desktop platforms you can
262         focus any widget that can accept user input, while on mobile platforms focus is
263         limited to widgets that accept text input (i.e., widgets that cause the virtual
264         keyboard to appear).
265         """
266         self._impl.focus()
267
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/core/src/toga/widgets/base.py b/core/src/toga/widgets/base.py
--- a/core/src/toga/widgets/base.py
+++ b/core/src/toga/widgets/base.py
@@ -154,12 +154,17 @@
         Any nominated child widget that is not a child of this widget will
         not have any change in parentage.
 
+        Refreshes the widget after removal if any children were removed.
+
         Raises ``ValueError`` if this widget cannot have children.
 
         :param children: The child nodes to remove.
         """
+        removed = False
+
         for child in children:
             if child.parent is self:
+                removed = True
                 super().remove(child)
 
                 child.app = None
@@ -167,9 +172,18 @@
 
                 self._impl.remove_child(child._impl)
 
-        if self.window:
+        if self.window and removed:
             self.window.content.refresh()
 
+    def clear(self):
+        """Remove all child widgets of this node.
+
+        Refreshes the widget after removal if any children were removed.
+
+        Raises ``ValueError`` if this widget cannot have children.
+        """
+        self.remove(*self.children)
+
     @property
     def app(self):
         """The App to which this widget belongs.

{"golden_diff": "diff --git a/core/src/toga/widgets/base.py b/core/src/toga/widgets/base.py\n--- a/core/src/toga/widgets/base.py\n+++ b/core/src/toga/widgets/base.py\n@@ -154,12 +154,17 @@\n         Any nominated child widget that is not a child of this widget will\n         not have any change in parentage.\n \n+        Refreshes the widget after removal if any children were removed.\n+\n         Raises ``ValueError`` if this widget cannot have children.\n \n         :param children: The child nodes to remove.\n         \"\"\"\n+        removed = False\n+\n         for child in children:\n             if child.parent is self:\n+                removed = True\n                 super().remove(child)\n \n                 child.app = None\n@@ -167,9 +172,18 @@\n \n                 self._impl.remove_child(child._impl)\n \n-        if self.window:\n+        if self.window and removed:\n             self.window.content.refresh()\n \n+    def clear(self):\n+        \"\"\"Remove all child widgets of this node.\n+\n+        Refreshes the widget after removal if any children were removed.\n+\n+        Raises ``ValueError`` if this widget cannot have children.\n+        \"\"\"\n+        self.remove(*self.children)\n+\n     @property\n     def app(self):\n         \"\"\"The App to which this widget belongs.\n", "issue": "Add a `clear()` method to remove all children\n### What is the problem or limitation you are having?\n\nAt present, you can:\r\n* add a single child to a widget (`widget.add(child)`)\r\n* remove a single child to a widget (`widget.remove(child)`)\r\n* add multiple children to a widget in a single call (`widget.add(child1, child2)`)\r\n* Remove multiple children from a widget in a single call  (`widget.remove(child1, child2)`)\r\n\r\nHowever, there is no API to remove *all* children from a node.\r\n\n\n### Describe the solution you'd like\n\n`widget.clear()` should remove all children from a widget. As of Travertino 0.2.0, a `clear()` API exists; however, invoking it could have unexpected consequences, as it doesn't include the Toga-side cleanups implied by this change.\n\n### Describe alternatives you've considered\n\n`widget.remove(*widget.children)` is a workaround at present, but isn't a great API.\n\n### Additional context\n\n_No response_\n", "before_files": [{"content": "from builtins import id as identifier\n\nfrom travertino.node import Node\n\nfrom toga.platform import get_platform_factory\nfrom toga.style import Pack, TogaApplicator\n\n\nclass WidgetRegistry(dict):\n    # WidgetRegistry is implemented as a subclass of dict, because it provides\n    # a mapping from ID to widget. However, it exposes a set-like API; add()\n    # and update() take instances to be added, and iteration is over values.\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n\n    def __setitem__(self, key, value):\n        # We do not want to allow setting items directly but to use the \"add\"\n        # method instead.\n        raise RuntimeError(\"Widgets cannot be directly added to a registry\")\n\n    def update(self, widgets):\n        for widget in widgets:\n            self.add(widget)\n\n    def add(self, widget):\n        if widget.id in self:\n            # Prevent from adding the same widget twice\n            # or adding 2 widgets with the same id\n            raise KeyError(f\"There is already a widget with the id {widget.id!r}\")\n        super().__setitem__(widget.id, widget)\n\n    def remove(self, id):\n        del self[id]\n\n    def __iter__(self):\n        return iter(self.values())\n\n\nclass Widget(Node):\n    _MIN_WIDTH = 100\n    _MIN_HEIGHT = 100\n\n    def __init__(\n        self,\n        id=None,\n        style=None,\n    ):\n        \"\"\"Create a base Toga widget.\n\n        This is an abstract base class; it cannot be instantiated.\n\n        :param id: The ID for the widget.\n        :param style: A style object. If no style is provided, a default style\n            will be applied to the widget.\n        \"\"\"\n        super().__init__(\n            style=style if style else Pack(),\n            applicator=TogaApplicator(self),\n        )\n\n        self._id = str(id) if id else str(identifier(self))\n        self._window = None\n        self._app = None\n        self._impl = None\n\n        self.factory = get_platform_factory()\n\n    def __repr__(self):\n        return f\"<{self.__class__.__name__}:0x{identifier(self):x}>\"\n\n    @property\n    def id(self):\n        \"\"\"The unique identifier for the widget.\"\"\"\n        return self._id\n\n    @property\n    def tab_index(self):\n        \"\"\"The position of the widget in the focus chain for the window.\n\n        .. note::\n\n            This is a beta feature. The ``tab_index`` API may change in\n            future.\n        \"\"\"\n        return self._impl.get_tab_index()\n\n    @tab_index.setter\n    def tab_index(self, tab_index):\n        self._impl.set_tab_index(tab_index)\n\n    def add(self, *children):\n        \"\"\"Add the provided widgets as children of this widget.\n\n        If a child widget already has a parent, it will be re-parented as a\n        child of this widget. If the child widget is already a child of this\n        widget, there is no change.\n\n        Raises ``ValueError`` if this widget cannot have children.\n\n        :param children: The widgets to add as children of this widget.\n        \"\"\"\n        for child in children:\n            if child.parent is not self:\n                # remove from old parent\n                if child.parent:\n                    child.parent.remove(child)\n\n                # add to new parent\n                super().add(child)\n\n                # set app and window\n                child.app = self.app\n                child.window = self.window\n\n                self._impl.add_child(child._impl)\n\n        if self.window:\n            self.window.content.refresh()\n\n    def insert(self, index, child):\n        \"\"\"Insert a widget as a child of this widget.\n\n        If a child widget already has a parent, it will be re-parented as a\n        child of this widget. If the child widget is already a child of this\n        widget, there is no change.\n\n        Raises ``ValueError`` if this node cannot have children.\n\n        :param index: The position in the list of children where the new widget\n            should be added.\n        :param child: The child to insert as a child of this node.\n        \"\"\"\n        if child.parent is not self:\n            # remove from old parent\n            if child.parent:\n                child.parent.remove(child)\n\n            # add to new parent\n            super().insert(index, child)\n\n            # set app and window\n            child.app = self.app\n            child.window = self.window\n\n            self._impl.insert_child(index, child._impl)\n\n        if self.window:\n            self.window.content.refresh()\n\n    def remove(self, *children):\n        \"\"\"Remove the provided widgets as children of this node.\n\n        Any nominated child widget that is not a child of this widget will\n        not have any change in parentage.\n\n        Raises ``ValueError`` if this widget cannot have children.\n\n        :param children: The child nodes to remove.\n        \"\"\"\n        for child in children:\n            if child.parent is self:\n                super().remove(child)\n\n                child.app = None\n                child.window = None\n\n                self._impl.remove_child(child._impl)\n\n        if self.window:\n            self.window.content.refresh()\n\n    @property\n    def app(self):\n        \"\"\"The App to which this widget belongs.\n\n        When setting the app for a widget, all children of this widget will be\n        recursively assigned to the same app.\n\n        Raises ``ValueError`` if the widget is already associated with another\n        app.\n        \"\"\"\n        return self._app\n\n    @app.setter\n    def app(self, app):\n        # If the widget is already assigned to an app\n        if self._app:\n            if self._app == app:\n                # If app is the same as the previous app, return\n                return\n\n            # Deregister the widget from the old app\n            self._app.widgets.remove(self.id)\n\n        self._app = app\n        self._impl.set_app(app)\n        for child in self.children:\n            child.app = app\n\n        if app is not None:\n            # Add this widget to the application widget registry\n            app.widgets.add(self)\n\n    @property\n    def window(self):\n        \"\"\"The window to which this widget belongs.\n\n        When setting the window for a widget, all children of this widget will be\n        recursively assigned to the same window.\n        \"\"\"\n        return self._window\n\n    @window.setter\n    def window(self, window):\n        # Remove the widget from the widget registry it is currently a part of\n        if self.window is not None:\n            self.window.widgets.remove(self.id)\n\n        self._window = window\n        self._impl.set_window(window)\n\n        for child in self.children:\n            child.window = window\n\n        if window is not None:\n            # Add this widget to the window's widget registry\n            window.widgets.add(self)\n\n    @property\n    def enabled(self):\n        \"\"\"Is the widget currently enabled? i.e., can the user interact with the widget?\"\"\"\n        return self._impl.get_enabled()\n\n    @enabled.setter\n    def enabled(self, value):\n        self._impl.set_enabled(bool(value))\n\n    def refresh(self):\n        self._impl.refresh()\n\n        # Refresh the layout\n        if self._root:\n            # We're not the root of the node heirarchy;\n            # defer the refresh call to the root node.\n            self._root.refresh()\n        else:\n            self.refresh_sublayouts()\n            # We can't compute a layout until we have a viewport\n            if self._impl.viewport:\n                super().refresh(self._impl.viewport)\n\n    def refresh_sublayouts(self):\n        for child in self.children:\n            child.refresh_sublayouts()\n\n    def focus(self):\n        \"\"\"Give this widget the input focus.\n\n        This method is a no-op if the widget can't accept focus. The ability of a widget\n        to accept focus is platform-dependent. In general, on desktop platforms you can\n        focus any widget that can accept user input, while on mobile platforms focus is\n        limited to widgets that accept text input (i.e., widgets that cause the virtual\n        keyboard to appear).\n        \"\"\"\n        self._impl.focus()\n", "path": "core/src/toga/widgets/base.py"}], "after_files": [{"content": "from builtins import id as identifier\n\nfrom travertino.node import Node\n\nfrom toga.platform import get_platform_factory\nfrom toga.style import Pack, TogaApplicator\n\n\nclass WidgetRegistry(dict):\n    # WidgetRegistry is implemented as a subclass of dict, because it provides\n    # a mapping from ID to widget. However, it exposes a set-like API; add()\n    # and update() take instances to be added, and iteration is over values.\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n\n    def __setitem__(self, key, value):\n        # We do not want to allow setting items directly but to use the \"add\"\n        # method instead.\n        raise RuntimeError(\"Widgets cannot be directly added to a registry\")\n\n    def update(self, widgets):\n        for widget in widgets:\n            self.add(widget)\n\n    def add(self, widget):\n        if widget.id in self:\n            # Prevent from adding the same widget twice\n            # or adding 2 widgets with the same id\n            raise KeyError(f\"There is already a widget with the id {widget.id!r}\")\n        super().__setitem__(widget.id, widget)\n\n    def remove(self, id):\n        del self[id]\n\n    def __iter__(self):\n        return iter(self.values())\n\n\nclass Widget(Node):\n    _MIN_WIDTH = 100\n    _MIN_HEIGHT = 100\n\n    def __init__(\n        self,\n        id=None,\n        style=None,\n    ):\n        \"\"\"Create a base Toga widget.\n\n        This is an abstract base class; it cannot be instantiated.\n\n        :param id: The ID for the widget.\n        :param style: A style object. If no style is provided, a default style\n            will be applied to the widget.\n        \"\"\"\n        super().__init__(\n            style=style if style else Pack(),\n            applicator=TogaApplicator(self),\n        )\n\n        self._id = str(id) if id else str(identifier(self))\n        self._window = None\n        self._app = None\n        self._impl = None\n\n        self.factory = get_platform_factory()\n\n    def __repr__(self):\n        return f\"<{self.__class__.__name__}:0x{identifier(self):x}>\"\n\n    @property\n    def id(self):\n        \"\"\"The unique identifier for the widget.\"\"\"\n        return self._id\n\n    @property\n    def tab_index(self):\n        \"\"\"The position of the widget in the focus chain for the window.\n\n        .. note::\n\n            This is a beta feature. The ``tab_index`` API may change in\n            future.\n        \"\"\"\n        return self._impl.get_tab_index()\n\n    @tab_index.setter\n    def tab_index(self, tab_index):\n        self._impl.set_tab_index(tab_index)\n\n    def add(self, *children):\n        \"\"\"Add the provided widgets as children of this widget.\n\n        If a child widget already has a parent, it will be re-parented as a\n        child of this widget. If the child widget is already a child of this\n        widget, there is no change.\n\n        Raises ``ValueError`` if this widget cannot have children.\n\n        :param children: The widgets to add as children of this widget.\n        \"\"\"\n        for child in children:\n            if child.parent is not self:\n                # remove from old parent\n                if child.parent:\n                    child.parent.remove(child)\n\n                # add to new parent\n                super().add(child)\n\n                # set app and window\n                child.app = self.app\n                child.window = self.window\n\n                self._impl.add_child(child._impl)\n\n        if self.window:\n            self.window.content.refresh()\n\n    def insert(self, index, child):\n        \"\"\"Insert a widget as a child of this widget.\n\n        If a child widget already has a parent, it will be re-parented as a\n        child of this widget. If the child widget is already a child of this\n        widget, there is no change.\n\n        Raises ``ValueError`` if this node cannot have children.\n\n        :param index: The position in the list of children where the new widget\n            should be added.\n        :param child: The child to insert as a child of this node.\n        \"\"\"\n        if child.parent is not self:\n            # remove from old parent\n            if child.parent:\n                child.parent.remove(child)\n\n            # add to new parent\n            super().insert(index, child)\n\n            # set app and window\n            child.app = self.app\n            child.window = self.window\n\n            self._impl.insert_child(index, child._impl)\n\n        if self.window:\n            self.window.content.refresh()\n\n    def remove(self, *children):\n        \"\"\"Remove the provided widgets as children of this node.\n\n        Any nominated child widget that is not a child of this widget will\n        not have any change in parentage.\n\n        Refreshes the widget after removal if any children were removed.\n\n        Raises ``ValueError`` if this widget cannot have children.\n\n        :param children: The child nodes to remove.\n        \"\"\"\n        removed = False\n\n        for child in children:\n            if child.parent is self:\n                removed = True\n                super().remove(child)\n\n                child.app = None\n                child.window = None\n\n                self._impl.remove_child(child._impl)\n\n        if self.window and removed:\n            self.window.content.refresh()\n\n    def clear(self):\n        \"\"\"Remove all child widgets of this node.\n\n        Refreshes the widget after removal if any children were removed.\n\n        Raises ``ValueError`` if this widget cannot have children.\n        \"\"\"\n        self.remove(*self.children)\n\n    @property\n    def app(self):\n        \"\"\"The App to which this widget belongs.\n\n        When setting the app for a widget, all children of this widget will be\n        recursively assigned to the same app.\n\n        Raises ``ValueError`` if the widget is already associated with another\n        app.\n        \"\"\"\n        return self._app\n\n    @app.setter\n    def app(self, app):\n        # If the widget is already assigned to an app\n        if self._app:\n            if self._app == app:\n                # If app is the same as the previous app, return\n                return\n\n            # Deregister the widget from the old app\n            self._app.widgets.remove(self.id)\n\n        self._app = app\n        self._impl.set_app(app)\n        for child in self.children:\n            child.app = app\n\n        if app is not None:\n            # Add this widget to the application widget registry\n            app.widgets.add(self)\n\n    @property\n    def window(self):\n        \"\"\"The window to which this widget belongs.\n\n        When setting the window for a widget, all children of this widget will be\n        recursively assigned to the same window.\n        \"\"\"\n        return self._window\n\n    @window.setter\n    def window(self, window):\n        # Remove the widget from the widget registry it is currently a part of\n        if self.window is not None:\n            self.window.widgets.remove(self.id)\n\n        self._window = window\n        self._impl.set_window(window)\n\n        for child in self.children:\n            child.window = window\n\n        if window is not None:\n            # Add this widget to the window's widget registry\n            window.widgets.add(self)\n\n    @property\n    def enabled(self):\n        \"\"\"Is the widget currently enabled? i.e., can the user interact with the widget?\"\"\"\n        return self._impl.get_enabled()\n\n    @enabled.setter\n    def enabled(self, value):\n        self._impl.set_enabled(bool(value))\n\n    def refresh(self):\n        self._impl.refresh()\n\n        # Refresh the layout\n        if self._root:\n            # We're not the root of the node heirarchy;\n            # defer the refresh call to the root node.\n            self._root.refresh()\n        else:\n            self.refresh_sublayouts()\n            # We can't compute a layout until we have a viewport\n            if self._impl.viewport:\n                super().refresh(self._impl.viewport)\n\n    def refresh_sublayouts(self):\n        for child in self.children:\n            child.refresh_sublayouts()\n\n    def focus(self):\n        \"\"\"Give this widget the input focus.\n\n        This method is a no-op if the widget can't accept focus. The ability of a widget\n        to accept focus is platform-dependent. In general, on desktop platforms you can\n        focus any widget that can accept user input, while on mobile platforms focus is\n        limited to widgets that accept text input (i.e., widgets that cause the virtual\n        keyboard to appear).\n        \"\"\"\n        self._impl.focus()\n", "path": "core/src/toga/widgets/base.py"}]}