Skip to content

toast module

Deprecated module path shim for ttkbootstrap.toast.

This module is deprecated. Use ttkbootstrap.widgets instead.

ToastNotification

A semi-transparent popup window for temporary alerts or messages. You may choose to display the toast for a specified period of time, otherwise you must click the toast to close it.

toast notification

Examples:

```python
import ttkbootstrap as ttk
from ttkbootstrap.toast import ToastNotification

app = ttk.Window()

toast = ToastNotification(
    title="ttkbootstrap toast message",
    message="This is a toast message",
    duration=3000,
)
toast.show_toast()

app.mainloop()
```
Source code in src/ttkbootstrap/widgets/toast.py
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
class ToastNotification:
    """A semi-transparent popup window for temporary alerts or messages.
    You may choose to display the toast for a specified period of time,
    otherwise you must click the toast to close it.

    ![toast notification](../assets/toast/toast.png)

    Examples:

        ```python
        import ttkbootstrap as ttk
        from ttkbootstrap.toast import ToastNotification

        app = ttk.Window()

        toast = ToastNotification(
            title="ttkbootstrap toast message",
            message="This is a toast message",
            duration=3000,
        )
        toast.show_toast()

        app.mainloop()
        ```
    """

    def __init__(
            self,
            title: str,
            message: str,
            duration: Optional[int] = None,
            bootstyle: str = LIGHT,
            alert: bool = False,
            icon: Optional[str] = None,
            iconfont: Optional[Union[font.Font, str]] = None,
            position: Optional[tuple[int, int, str]] = None,
            **kwargs: Any,
    ) -> None:
        """
        Parameters:

            title (str):
                The toast title.

            message (str):
                The toast message.

            duration (int):
                The number of milliseconds to show the toast. If None
                (default), then you must click the toast to close it.

            bootstyle (str):
                Style keywords used to updated the label style. One of
                the accepted color keywords.

            alert (bool):
                Indicates whether to ring the display bell when the
                toast is shown.

            icon (str):
                A UNICODE character to display on the top-left hand
                corner of the toast. The default symbol is OS specific.
                Pass an empty string to remove the symbol.

            iconfont (Union[str, Font]):
                The font used to render the icon. By default, this is
                OS specific. You may need to change the font to enable
                better character or emoji support for the icon you
                want to use. Windows (Segoe UI Symbol),
                Linux (FreeSerif), macOS (Apple Symbol)

            position (tuple[int, int, str]):
                A tuple that controls the position of the toast. Default
                is OS specific. The tuple cooresponds to
                (horizontal, vertical, anchor), where the horizontal and
                vertical elements represent the position of the toplevel
                releative to the anchor, which is "ne" or top-left by
                default. Acceptable anchors include: n, e, s, w, nw, ne,
                sw, se. For example: (100, 100, 'ne').

            **kwargs (Dict):
                Other keyword arguments passed to the `Toplevel` window.
        """
        self.container = None
        self.message = message
        self.title = title
        self.duration = duration
        self.bootstyle = bootstyle
        self.icon = icon
        self.iconfont = iconfont
        self.iconfont = None
        self.titlefont = None
        self.toplevel = None
        self.kwargs = kwargs
        self.alert = alert
        self.position = position

        if "overrideredirect" not in self.kwargs:
            self.kwargs["overrideredirect"] = True
        if "alpha" not in self.kwargs:
            self.kwargs["alpha"] = 0.95

        if position is not None:
            if len(position) != 3:
                self.position = None

    def show_toast(self, *_: Any) -> None:
        """Create and show the toast window."""
        # Late import to avoid circular import during package initialization
        from ttkbootstrap import Frame, Label, Toplevel, utility

        # build toast
        self.toplevel = Toplevel(**self.kwargs)
        self._setup(self.toplevel)

        self.container = Frame(self.toplevel, bootstyle=self.bootstyle)
        self.container.pack(fill=BOTH, expand=YES)
        Label(
            self.container,
            text=self.icon,
            font=self.iconfont,
            bootstyle=f"{self.bootstyle}-inverse",
            anchor=NW,
        ).grid(row=0, column=0, rowspan=2, sticky=NSEW, padx=(5, 0))
        Label(
            self.container,
            text=self.title,
            font=self.titlefont,
            bootstyle=f"{self.bootstyle}-inverse",
            anchor=NW,
        ).grid(row=0, column=1, sticky=NSEW, padx=10, pady=(5, 0))
        Label(
            self.container,
            text=self.message,
            wraplength=utility.scale_size(self.toplevel, 300),
            bootstyle=f"{self.bootstyle}-inverse",
            anchor=NW,
        ).grid(row=1, column=1, sticky=NSEW, padx=10, pady=(0, 5))

        self.toplevel.bind("<ButtonPress>", self.hide_toast)

        # alert toast
        if self.alert:
            self.toplevel.bell()

        # specified duration to close
        if self.duration:
            self.toplevel.after(self.duration, self.hide_toast)

    def hide_toast(self, *_: Any) -> None:
        """Destroy and close the toast window."""
        try:
            alpha = float(self.toplevel.attributes("-alpha"))
            if alpha <= 0.1:
                self.toplevel.destroy()
            else:
                self.toplevel.attributes("-alpha", alpha - 0.1)
                self.toplevel.after(25, self.hide_toast)
        except:
            if self.toplevel:
                self.toplevel.destroy()

    def _setup(self, window) -> None:
        winsys = window.tk.call("tk", "windowingsystem")

        self.toplevel.configure(relief=RAISED)

        # minsize
        if "minsize" not in self.kwargs:
            # Late import to avoid circular import for utility
            from ttkbootstrap import utility
            w, h = utility.scale_size(self.toplevel, [300, 75])
            self.toplevel.minsize(w, h)

        # heading font
        _font = font.nametofont("TkDefaultFont")
        self.titlefont = font.Font(
            family=_font["family"],
            size=_font["size"] + 1,
            weight="bold",
        )
        # symbol font
        self.iconfont = font.Font(size=30, weight="bold")
        if winsys == "win32":
            self.iconfont["family"] = "Segoe UI Symbol"
            self.icon = DEFAULT_ICON_WIN32 if self.icon is None else self.icon
            if self.position is None:
                from ttkbootstrap import utility
                x, y = utility.scale_size(self.toplevel, [5, 50])
                self.position = (x, y, SE)
        elif winsys == "x11":
            self.iconfont["family"] = "FreeSerif"
            self.icon = DEFAULT_ICON if self.icon is None else self.icon
            if self.position is None:
                from ttkbootstrap import utility
                x, y = utility.scale_size(self.toplevel, [0, 0])
                self.position = (x, y, SE)
        else:
            self.iconfont["family"] = "Apple Symbols"
            self.toplevel.update_idletasks()
            self.icon = DEFAULT_ICON if self.icon is None else self.icon
            if self.position is None:
                from ttkbootstrap import utility
                x, y = utility.scale_size(self.toplevel, [50, 50])
                self.position = (x, y, NE)

        self.set_geometry()

    def set_geometry(self) -> None:
        self.toplevel.update_idletasks()  # actualize geometry
        anchor = self.position[-1]
        x_anchor = "-" if "w" not in anchor else "+"
        y_anchor = "-" if "n" not in anchor else "+"
        screen_w = self.toplevel.winfo_screenwidth() // 2
        screen_h = self.toplevel.winfo_screenheight() // 2
        top_w = self.toplevel.winfo_width() // 2
        top_h = self.toplevel.winfo_height() // 2

        if all(["e" not in anchor, "w" not in anchor]):
            xpos = screen_w - top_w
        else:
            xpos = self.position[0]
        if all(["n" not in anchor, "s" not in anchor]):
            ypos = screen_h - top_h
        else:
            ypos = self.position[1]

        self.toplevel.geometry(f"{x_anchor}{xpos}{y_anchor}{ypos}")

__init__(title, message, duration=None, bootstyle=LIGHT, alert=False, icon=None, iconfont=None, position=None, **kwargs)

Parameters:

title (str):
    The toast title.

message (str):
    The toast message.

duration (int):
    The number of milliseconds to show the toast. If None
    (default), then you must click the toast to close it.

bootstyle (str):
    Style keywords used to updated the label style. One of
    the accepted color keywords.

alert (bool):
    Indicates whether to ring the display bell when the
    toast is shown.

icon (str):
    A UNICODE character to display on the top-left hand
    corner of the toast. The default symbol is OS specific.
    Pass an empty string to remove the symbol.

iconfont (Union[str, Font]):
    The font used to render the icon. By default, this is
    OS specific. You may need to change the font to enable
    better character or emoji support for the icon you
    want to use. Windows (Segoe UI Symbol),
    Linux (FreeSerif), macOS (Apple Symbol)

position (tuple[int, int, str]):
    A tuple that controls the position of the toast. Default
    is OS specific. The tuple cooresponds to
    (horizontal, vertical, anchor), where the horizontal and
    vertical elements represent the position of the toplevel
    releative to the anchor, which is "ne" or top-left by
    default. Acceptable anchors include: n, e, s, w, nw, ne,
    sw, se. For example: (100, 100, 'ne').

**kwargs (Dict):
    Other keyword arguments passed to the `Toplevel` window.
Source code in src/ttkbootstrap/widgets/toast.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def __init__(
        self,
        title: str,
        message: str,
        duration: Optional[int] = None,
        bootstyle: str = LIGHT,
        alert: bool = False,
        icon: Optional[str] = None,
        iconfont: Optional[Union[font.Font, str]] = None,
        position: Optional[tuple[int, int, str]] = None,
        **kwargs: Any,
) -> None:
    """
    Parameters:

        title (str):
            The toast title.

        message (str):
            The toast message.

        duration (int):
            The number of milliseconds to show the toast. If None
            (default), then you must click the toast to close it.

        bootstyle (str):
            Style keywords used to updated the label style. One of
            the accepted color keywords.

        alert (bool):
            Indicates whether to ring the display bell when the
            toast is shown.

        icon (str):
            A UNICODE character to display on the top-left hand
            corner of the toast. The default symbol is OS specific.
            Pass an empty string to remove the symbol.

        iconfont (Union[str, Font]):
            The font used to render the icon. By default, this is
            OS specific. You may need to change the font to enable
            better character or emoji support for the icon you
            want to use. Windows (Segoe UI Symbol),
            Linux (FreeSerif), macOS (Apple Symbol)

        position (tuple[int, int, str]):
            A tuple that controls the position of the toast. Default
            is OS specific. The tuple cooresponds to
            (horizontal, vertical, anchor), where the horizontal and
            vertical elements represent the position of the toplevel
            releative to the anchor, which is "ne" or top-left by
            default. Acceptable anchors include: n, e, s, w, nw, ne,
            sw, se. For example: (100, 100, 'ne').

        **kwargs (Dict):
            Other keyword arguments passed to the `Toplevel` window.
    """
    self.container = None
    self.message = message
    self.title = title
    self.duration = duration
    self.bootstyle = bootstyle
    self.icon = icon
    self.iconfont = iconfont
    self.iconfont = None
    self.titlefont = None
    self.toplevel = None
    self.kwargs = kwargs
    self.alert = alert
    self.position = position

    if "overrideredirect" not in self.kwargs:
        self.kwargs["overrideredirect"] = True
    if "alpha" not in self.kwargs:
        self.kwargs["alpha"] = 0.95

    if position is not None:
        if len(position) != 3:
            self.position = None

hide_toast(*_)

Destroy and close the toast window.

Source code in src/ttkbootstrap/widgets/toast.py
206
207
208
209
210
211
212
213
214
215
216
217
def hide_toast(self, *_: Any) -> None:
    """Destroy and close the toast window."""
    try:
        alpha = float(self.toplevel.attributes("-alpha"))
        if alpha <= 0.1:
            self.toplevel.destroy()
        else:
            self.toplevel.attributes("-alpha", alpha - 0.1)
            self.toplevel.after(25, self.hide_toast)
    except:
        if self.toplevel:
            self.toplevel.destroy()

show_toast(*_)

Create and show the toast window.

Source code in src/ttkbootstrap/widgets/toast.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
def show_toast(self, *_: Any) -> None:
    """Create and show the toast window."""
    # Late import to avoid circular import during package initialization
    from ttkbootstrap import Frame, Label, Toplevel, utility

    # build toast
    self.toplevel = Toplevel(**self.kwargs)
    self._setup(self.toplevel)

    self.container = Frame(self.toplevel, bootstyle=self.bootstyle)
    self.container.pack(fill=BOTH, expand=YES)
    Label(
        self.container,
        text=self.icon,
        font=self.iconfont,
        bootstyle=f"{self.bootstyle}-inverse",
        anchor=NW,
    ).grid(row=0, column=0, rowspan=2, sticky=NSEW, padx=(5, 0))
    Label(
        self.container,
        text=self.title,
        font=self.titlefont,
        bootstyle=f"{self.bootstyle}-inverse",
        anchor=NW,
    ).grid(row=0, column=1, sticky=NSEW, padx=10, pady=(5, 0))
    Label(
        self.container,
        text=self.message,
        wraplength=utility.scale_size(self.toplevel, 300),
        bootstyle=f"{self.bootstyle}-inverse",
        anchor=NW,
    ).grid(row=1, column=1, sticky=NSEW, padx=10, pady=(0, 5))

    self.toplevel.bind("<ButtonPress>", self.hide_toast)

    # alert toast
    if self.alert:
        self.toplevel.bell()

    # specified duration to close
    if self.duration:
        self.toplevel.after(self.duration, self.hide_toast)

Window

Bases: Tk

A class that wraps the tkinter.Tk class in order to provide a more convenient api with additional bells and whistles. For more information on how to use the inherited Tk methods, see the tcl/tk documentation and the Python documentation.

Examples:

```python
app = Window(title="My Application", themename="superhero")
app.mainloop()
```
Source code in src/ttkbootstrap/window.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
class Window(tkinter.Tk):
    """A class that wraps the tkinter.Tk class in order to provide a
    more convenient api with additional bells and whistles. For more
    information on how to use the inherited `Tk` methods, see the
    [tcl/tk documentation](https://tcl.tk/man/tcl8.6/TkCmd/wm.htm)
    and the [Python documentation](https://docs.python.org/3/library/tkinter.html#tkinter.Tk).

    ![](../../assets/window/window-toplevel.png)

    Examples:

        ```python
        app = Window(title="My Application", themename="superhero")
        app.mainloop()
        ```
    """

    def __init__(
            self,
            title: str = "ttkbootstrap",
            themename: str = "litera",
            iconphoto: Optional[str] = '',
            size: Optional[Tuple[int, int]] = None,
            position: Optional[Tuple[int, int]] = None,
            minsize: Optional[Tuple[int, int]] = None,
            maxsize: Optional[Tuple[int, int]] = None,
            resizable: Optional[Tuple[bool, bool]] = None,
            hdpi: bool = True,
            scaling: Optional[float] = None,
            transient: Optional[tkinter.Misc] = None,
            overrideredirect: bool = False,
            alpha: float = 1.0,
            **kwargs: Any,
    ) -> None:
        """
        Parameters:

            title (str):
                The title that appears on the application titlebar.

            themename (str):
                The name of the ttkbootstrap theme to apply to the
                application.

            iconphoto (str):
                A path to the image used for the titlebar icon.
                Internally this is passed to the `Tk.iconphoto` method
                and the image will be the default icon for all windows.
                A ttkbootstrap image is used by default. To disable
                this default behavior, set the value to `None` and use
                the `Tk.iconphoto` or `Tk.iconbitmap` methods directly.

            size (tuple[int, int]):
                The width and height of the application window.
                Internally, this argument is passed to the
                `Window.geometry` method.

            position (tuple[int, int]):
                The horizontal and vertical position of the window on
                the screen relative to the top-left coordinate.
                Internally this is passed to the `Window.geometry`
                method.

            minsize (tuple[int, int]):
                Specifies the minimum permissible dimensions for the
                window. Internally, this argument is passed to the
                `Window.minsize` method.

            maxsize (tuple[int, int]):
                Specifies the maximum permissible dimensions for the
                window. Internally, this argument is passed to the
                `Window.maxsize` method.

            resizable (tuple[bool, bool]):
                Specifies whether the user may interactively resize the
                toplevel window. Must pass in two arguments that specify
                this flag for _horizontal_ and _vertical_ dimensions.
                This can be adjusted after the window is created by using
                the `Window.resizable` method.

            hdpi (bool):
                Enable high-dpi support for Windows OS. This option is
                enabled by default.

            scaling (float):
                Sets the current scaling factor used by Tk to convert
                between physical units (for example, points, inches, or
                millimeters) and pixels. The number argument is a
                floating point number that specifies the number of pixels
                per point on window's display.

            transient (Union[Tk, Widget]):
                Instructs the window manager that this widget is
                transient with regard to the widget master. Internally
                this is passed to the `Window.transient` method.

            overrideredirect (bool):
                Instructs the window manager to ignore this widget if
                True. Internally, this argument is passed to the
                `Window.overrideredirect(1)` method.

            alpha (float):
                On Windows, specifies the alpha transparency level of the
                toplevel. Where not supported, alpha remains at 1.0. Internally,
                this is processed as `Toplevel.attributes('-alpha', alpha)`.

            **kwargs:
                Any other keyword arguments that are passed through to tkinter.Tk() constructor
                List of available keywords available at: https://docs.python.org/3/library/tkinter.html#tkinter.Tk
        """
        if hdpi:
            utility.enable_high_dpi_awareness()

        super().__init__(**kwargs)
        self.winsys: str = self.tk.call('tk', 'windowingsystem')

        if scaling is not None:
            utility.enable_high_dpi_awareness(self, scaling)

        if iconphoto is not None:
            if iconphoto == '':
                # the default ttkbootstrap icon
                self._icon = tkinter.PhotoImage(master=self, data=Icon.icon)
                self.iconphoto(True, self._icon)
            else:
                try:
                    # the user provided an image path
                    self._icon = tkinter.PhotoImage(file=iconphoto, master=self)
                    self.iconphoto(True, self._icon)
                except tkinter.TclError:
                    # The fallback icon if the user icon fails.
                    print('iconphoto path is bad; using default image.')
                    self._icon = tkinter.PhotoImage(data=Icon.icon, master=self)
                    self.iconphoto(True, self._icon)

        self.title(title)

        if size is not None:
            width, height = size
            self.geometry(f"{width}x{height}")

        if position is not None:
            xpos, ypos = position
            self.geometry(f"+{xpos}+{ypos}")

        if minsize is not None:
            width, height = minsize
            self.minsize(width, height)

        if maxsize is not None:
            width, height = maxsize
            self.maxsize(width, height)

        if resizable is not None:
            width, height = resizable
            self.resizable(width, height)

        if transient is not None:
            self.transient(transient)

        if overrideredirect:
            self.overrideredirect(1)

        if alpha is not None:
            if self.winsys == 'x11':
                self.alpha = alpha
                self.alpha_bind = self.bind("<Visibility>", on_visibility, '+')
            else:
                self.attributes("-alpha", alpha)

        apply_class_bindings(self)
        apply_all_bindings(self)
        self._style = Style(themename)

    @property
    def style(self) -> Style:
        """Return a reference to the `ttkbootstrap.style.Style` object."""
        return self._style

    def destroy(self) -> None:
        """Destroy the window and all its children."""
        self._style.instance = None
        super().destroy()

    def place_window_center(self) -> None:
        """Position the toplevel in the center of the screen. Does not
        account for titlebar height."""
        self.update_idletasks()
        w_height = self.winfo_height()
        w_width = self.winfo_width()
        s_height = self.winfo_screenheight()
        s_width = self.winfo_screenwidth()
        xpos = (s_width - w_width) // 2
        ypos = (s_height - w_height) // 2
        self.geometry(f'+{xpos}+{ypos}')

    position_center = place_window_center  # alias

style property

Return a reference to the ttkbootstrap.style.Style object.

__init__(title='ttkbootstrap', themename='litera', iconphoto='', size=None, position=None, minsize=None, maxsize=None, resizable=None, hdpi=True, scaling=None, transient=None, overrideredirect=False, alpha=1.0, **kwargs)

Parameters:

title (str):
    The title that appears on the application titlebar.

themename (str):
    The name of the ttkbootstrap theme to apply to the
    application.

iconphoto (str):
    A path to the image used for the titlebar icon.
    Internally this is passed to the `Tk.iconphoto` method
    and the image will be the default icon for all windows.
    A ttkbootstrap image is used by default. To disable
    this default behavior, set the value to `None` and use
    the `Tk.iconphoto` or `Tk.iconbitmap` methods directly.

size (tuple[int, int]):
    The width and height of the application window.
    Internally, this argument is passed to the
    `Window.geometry` method.

position (tuple[int, int]):
    The horizontal and vertical position of the window on
    the screen relative to the top-left coordinate.
    Internally this is passed to the `Window.geometry`
    method.

minsize (tuple[int, int]):
    Specifies the minimum permissible dimensions for the
    window. Internally, this argument is passed to the
    `Window.minsize` method.

maxsize (tuple[int, int]):
    Specifies the maximum permissible dimensions for the
    window. Internally, this argument is passed to the
    `Window.maxsize` method.

resizable (tuple[bool, bool]):
    Specifies whether the user may interactively resize the
    toplevel window. Must pass in two arguments that specify
    this flag for _horizontal_ and _vertical_ dimensions.
    This can be adjusted after the window is created by using
    the `Window.resizable` method.

hdpi (bool):
    Enable high-dpi support for Windows OS. This option is
    enabled by default.

scaling (float):
    Sets the current scaling factor used by Tk to convert
    between physical units (for example, points, inches, or
    millimeters) and pixels. The number argument is a
    floating point number that specifies the number of pixels
    per point on window's display.

transient (Union[Tk, Widget]):
    Instructs the window manager that this widget is
    transient with regard to the widget master. Internally
    this is passed to the `Window.transient` method.

overrideredirect (bool):
    Instructs the window manager to ignore this widget if
    True. Internally, this argument is passed to the
    `Window.overrideredirect(1)` method.

alpha (float):
    On Windows, specifies the alpha transparency level of the
    toplevel. Where not supported, alpha remains at 1.0. Internally,
    this is processed as `Toplevel.attributes('-alpha', alpha)`.

**kwargs:
    Any other keyword arguments that are passed through to tkinter.Tk() constructor
    List of available keywords available at: https://docs.python.org/3/library/tkinter.html#tkinter.Tk
Source code in src/ttkbootstrap/window.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
def __init__(
        self,
        title: str = "ttkbootstrap",
        themename: str = "litera",
        iconphoto: Optional[str] = '',
        size: Optional[Tuple[int, int]] = None,
        position: Optional[Tuple[int, int]] = None,
        minsize: Optional[Tuple[int, int]] = None,
        maxsize: Optional[Tuple[int, int]] = None,
        resizable: Optional[Tuple[bool, bool]] = None,
        hdpi: bool = True,
        scaling: Optional[float] = None,
        transient: Optional[tkinter.Misc] = None,
        overrideredirect: bool = False,
        alpha: float = 1.0,
        **kwargs: Any,
) -> None:
    """
    Parameters:

        title (str):
            The title that appears on the application titlebar.

        themename (str):
            The name of the ttkbootstrap theme to apply to the
            application.

        iconphoto (str):
            A path to the image used for the titlebar icon.
            Internally this is passed to the `Tk.iconphoto` method
            and the image will be the default icon for all windows.
            A ttkbootstrap image is used by default. To disable
            this default behavior, set the value to `None` and use
            the `Tk.iconphoto` or `Tk.iconbitmap` methods directly.

        size (tuple[int, int]):
            The width and height of the application window.
            Internally, this argument is passed to the
            `Window.geometry` method.

        position (tuple[int, int]):
            The horizontal and vertical position of the window on
            the screen relative to the top-left coordinate.
            Internally this is passed to the `Window.geometry`
            method.

        minsize (tuple[int, int]):
            Specifies the minimum permissible dimensions for the
            window. Internally, this argument is passed to the
            `Window.minsize` method.

        maxsize (tuple[int, int]):
            Specifies the maximum permissible dimensions for the
            window. Internally, this argument is passed to the
            `Window.maxsize` method.

        resizable (tuple[bool, bool]):
            Specifies whether the user may interactively resize the
            toplevel window. Must pass in two arguments that specify
            this flag for _horizontal_ and _vertical_ dimensions.
            This can be adjusted after the window is created by using
            the `Window.resizable` method.

        hdpi (bool):
            Enable high-dpi support for Windows OS. This option is
            enabled by default.

        scaling (float):
            Sets the current scaling factor used by Tk to convert
            between physical units (for example, points, inches, or
            millimeters) and pixels. The number argument is a
            floating point number that specifies the number of pixels
            per point on window's display.

        transient (Union[Tk, Widget]):
            Instructs the window manager that this widget is
            transient with regard to the widget master. Internally
            this is passed to the `Window.transient` method.

        overrideredirect (bool):
            Instructs the window manager to ignore this widget if
            True. Internally, this argument is passed to the
            `Window.overrideredirect(1)` method.

        alpha (float):
            On Windows, specifies the alpha transparency level of the
            toplevel. Where not supported, alpha remains at 1.0. Internally,
            this is processed as `Toplevel.attributes('-alpha', alpha)`.

        **kwargs:
            Any other keyword arguments that are passed through to tkinter.Tk() constructor
            List of available keywords available at: https://docs.python.org/3/library/tkinter.html#tkinter.Tk
    """
    if hdpi:
        utility.enable_high_dpi_awareness()

    super().__init__(**kwargs)
    self.winsys: str = self.tk.call('tk', 'windowingsystem')

    if scaling is not None:
        utility.enable_high_dpi_awareness(self, scaling)

    if iconphoto is not None:
        if iconphoto == '':
            # the default ttkbootstrap icon
            self._icon = tkinter.PhotoImage(master=self, data=Icon.icon)
            self.iconphoto(True, self._icon)
        else:
            try:
                # the user provided an image path
                self._icon = tkinter.PhotoImage(file=iconphoto, master=self)
                self.iconphoto(True, self._icon)
            except tkinter.TclError:
                # The fallback icon if the user icon fails.
                print('iconphoto path is bad; using default image.')
                self._icon = tkinter.PhotoImage(data=Icon.icon, master=self)
                self.iconphoto(True, self._icon)

    self.title(title)

    if size is not None:
        width, height = size
        self.geometry(f"{width}x{height}")

    if position is not None:
        xpos, ypos = position
        self.geometry(f"+{xpos}+{ypos}")

    if minsize is not None:
        width, height = minsize
        self.minsize(width, height)

    if maxsize is not None:
        width, height = maxsize
        self.maxsize(width, height)

    if resizable is not None:
        width, height = resizable
        self.resizable(width, height)

    if transient is not None:
        self.transient(transient)

    if overrideredirect:
        self.overrideredirect(1)

    if alpha is not None:
        if self.winsys == 'x11':
            self.alpha = alpha
            self.alpha_bind = self.bind("<Visibility>", on_visibility, '+')
        else:
            self.attributes("-alpha", alpha)

    apply_class_bindings(self)
    apply_all_bindings(self)
    self._style = Style(themename)

destroy()

Destroy the window and all its children.

Source code in src/ttkbootstrap/window.py
344
345
346
347
def destroy(self) -> None:
    """Destroy the window and all its children."""
    self._style.instance = None
    super().destroy()

place_window_center()

Position the toplevel in the center of the screen. Does not account for titlebar height.

Source code in src/ttkbootstrap/window.py
349
350
351
352
353
354
355
356
357
358
359
def place_window_center(self) -> None:
    """Position the toplevel in the center of the screen. Does not
    account for titlebar height."""
    self.update_idletasks()
    w_height = self.winfo_height()
    w_width = self.winfo_width()
    s_height = self.winfo_screenheight()
    s_width = self.winfo_screenwidth()
    xpos = (s_width - w_width) // 2
    ypos = (s_height - w_height) // 2
    self.geometry(f'+{xpos}+{ypos}')