TopLevel

A second, independent window — its own native window with a title bar, separate from the main application window. Use it for tool windows, secondary documents, or custom dialogs that need more than sw.dialog offers.

A TopLevel is a container: fill it with children and lay them out just like the main window.

Example

const win = app.TopLevel();
win.wm.title('About');
win.wm.geometry('320x180');

win.TLabel({ text: 'ScriptWeaver', font: '{Segoe UI} 16 bold' }).pack.configure({
  pady: 16,
});
win.TButton({ text: 'Close', onClick: () => win.destroy() }).pack.configure();

// Closing via the title-bar [x] destroys it too.
win.wm.protocol('WM_DELETE_WINDOW', () => win.destroy());

Window management

A TopLevel carries the same wm proxy as the main window:

Call Description
win.wm.title(text) Set the title-bar text.
win.wm.geometry('WxH+X+Y') Set size and/or position.
win.wm.minsize(w, h) / maxsize(w, h) Constrain resizing.
win.wm.protocol('WM_DELETE_WINDOW', fn) Run fn when the user closes the window.
win.wm.withdraw() / deiconify() Hide / show the window.

For a modal dialog, take a grab so input stays in the window (win.grab.set()), and release it when done (win.grab.release()).

Options

Option Type Description
width / height number Requested size in pixels (usually set via wm.geometry instead).
background string Window background colour.
menu Menu A menu bar for this window.

Methods

destroy() closes the window (and its children). Plus the inherited widget methods and the container factory methods — see Widget basics.

See also