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
Copy dialog = Dialog (
title = "Dialog Window" ,
content = None ,
size = "small" ,
)
Parameters
Parameters
Type
Description
Title of the dialog window
Widget to display in dialog window
Literal["tiny", "small", "large", "full"] = "small"
Size of the dialog window
title
Title of the dialog window that will be displayed in the header.
type: str
default value: ""
Copy 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
Copy 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"
Copy 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
Attributes and Methods
Description
Open (show) dialog window.
Close (hide) dialog window.
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
Copy 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:
Copy load_dotenv ( "local.env" )
load_dotenv (os.path. expanduser ( "~/supervisely.env" ))
api = sly . Api ()
Initialize content widgets for Dialog
Copy 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
Copy dialog = Dialog (title = "Dialog window" , content = dialog_container, size = "small" )
Create button to open Dialog
Copy 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.
Copy card = Card (title = "Dialog" , content = open_dialog_btn)
Create app using layout
Add Container widget with card and dialog widgets to the app layout.
Copy app = sly . Application (layout = Container ([card, dialog]))
Add button click event to update open and close Dialog
Copy @open_dialog_btn . click
def show_dialog ():
dialog . show ()
@close_dialog_btn . click
def hide_dialog ():
dialog . hide ()