Window Widgets

MainWindow

The MainWindow represents the main window for an application. There should only be one MainWindow in each application.

Here is a list of styles you can customize on MainWindow:

background_color (color): the background color of the main window.

margin_height (float): the height distance between the window content and the window border.

margin_width (float): the width distance between the window content and the window border.

Here is an example of a main window with style. Click the button to show the main window. Since the example is running within a MainWindow already, creating a new MainWindow will not run correctly in this example, but it demonstrates how to set the style of the MainWindow. And note the style of MainWindow is not propagated to other windows.

![Code Result](Window Widgets_0.png)

from omni.ui import color as cl

self._main_window = None
self._window1 = None
self._window2 = None
def create_main_window():
    if not self._main_window:
        self._main_window = ui.MainWindow()
        self._main_window.main_frame.set_style({
            "MainWindow": {
                "background_color": cl.purple,
                "margin_height": 20,
                "margin_width": 10
            }})
        self._window1 = ui.Window("window 1", width=300, height=300)
        self._window2 = ui.Window("window 2", width=300, height=300)
        main_dockspace = ui.Workspace.get_window("DockSpace")
        self._window1.dock_in(main_dockspace, ui.DockPosition.SAME)
        self._window2.dock_in(main_dockspace, ui.DockPosition.SAME)
        self._window2.focus()
    self._window2.visible = True

ui.Button("click for Main Window", width=180, clicked_fn=create_main_window)

Window

The window is a child window of the MainWindow. And it can be docked. You can have any type of widgets as the window content widgets.

Here is a list of styles you can customize on Window:

background_color (color): the background color of the window.

border_color (color): the border color if the window has a border.

border_radius (float): the radius of the corner angle if the user wants to round the window.

border_width (float): the border width if the window has a border.

Here is an example of a window with style. Click the button to show the window.

![Code Result](Window Widgets_1.png)

from omni.ui import color as cl

self._style_window_example = None
def create_styled_window():
    if not self._style_window_example:
        self._style_window_example = ui.Window("Styled Window Example", width=300, height=300)
        self._style_window_example.frame.set_style({
            "Window": {
                "background_color": cl.blue,
                "border_radius": 10,
                "border_width": 5,
                "border_color": cl.red,
            }})
        self._style_window_example.visible = True

ui.Button("click for Styled Window", width=180, clicked_fn=create_styled_window)

Note that a window’s style is set from its frame since ui.Window itself is not a widget. We can’t set style to it like other widgets. ui.Window’s frame is a normal ui.Frame widget which itself doesn’t have styles like background_color or border_radius (see Container Widgets->Frame). We specifically interpret the input ui.Window’s frame style as the window style here. Therefore, the window style is not propagated to the content widget either just like the MainWindow.

If you want to set up a default style for the entire window. You should use ui.style.default. More details in The Style Sheet Syntax -> Style Override -> Default style override.