Dialog
Introduction
Dialog
is a widget that allows to show a dialog window that contain any other widgets. It can be used to show a message to the user or to ask for confirmation.
Read this tutorial in developer portal.
Function signature
dialog = Dialog(
title = "Dialog Window",
content = None,
size = "small",
)
Parameters
title
str
Title of the dialog window
content
Widget
Widget to display in dialog window
size
Literal["tiny", "small", "large", "full"] = "small"
Size of the dialog window
widget_id
str
ID of the widget
title
Title of the dialog window that will be displayed in the header.
type: str
default value: ""
dialog = Dialog(title="Dialog Window")
content
Widget to display in the dialog window. Use Container
widget to display multiple widgets.
type: Widget
default value: None
dialog_container = Container(
[Text(text="Hello world!", status="text", font_size=32), Button("Click me!")]
)
dialog = Dialog(
title = "Dialog Window",
content = dialog_container,
size = "small",
)
size
Width of the annotation border (contour) line. Set to 0 to hide a line.
type: Literal["tiny", "small", "large", "full"]
default value: "small"
dialog_container = Container(
[Text(text="Hello world!", status="text", font_size=32), Button("Click me!")]
)
dialog = Dialog(
title = "Dialog Window",
content = dialog_container,
size = "large",
)
widget_id
ID of the widget.
type: str
default value: None
Methods and attributes
show()
Open (show) dialog window.
hide()
Close (hide) dialog window.
title
Set title for dialog window
Mini App Example
You can find this example in our Github repository: supervisely-ecosystem/ui-widgets-demos/layouts and containers/016_dialog/src/main.py
Import libraries
import os
import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Button, Card, Container, Dialog, Text
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))
api = sly.Api()
Initialize content widgets for Dialog
dialog_text = Text(text="Hello world!", status="text", font_size=32)
close_dialog_btn = Button("Click me!")
dialog_container = Container([dialog_text, close_dialog_btn])
Initialize Dialog widget
dialog = Dialog(title="Dialog window", content=dialog_container, size="small")
Create button to open Dialog
open_dialog_btn = Button("Open dialog")
Create app layout
Prepare a layout for app using Card
widget with the content
parameter and place Button for opening dialog to the content.
card = Card(title="Dialog", content=open_dialog_btn)
Create app using layout
Add Container widget with card and dialog widgets to the app layout.
app = sly.Application(layout=Container([card, dialog]))
Add button click event to update open and close Dialog
@open_dialog_btn.click
def show_dialog():
dialog.show()
@close_dialog_btn.click
def hide_dialog():
dialog.hide()
Last updated
Was this helpful?