IntroductionInstallationLimitations of the "file" protocolFrequently asked questionsSyntax, keywords and built-in functionsStandard distributionimport implementationBrython packagesBrowser interface
Introduction - DOM API
Creating a document Accessing elements Attributes, properties and methods Events Mouse events Keyboard events Focus events Drag events Query string Interactions with Javascript Brython-specific built-in modules
browser
browser.aio browser.ajax browser.html browser.local_storage browser.markdown browser.object_storage browser.session_storage browser.svg browser.template browser.timer browser.webcomponent browser.websocket browser.worker Widgets browser.widgets.dialog browser.widgets.menu interpreter javascript Working with BrythonCookbook |
browser.widgets.dialogThis module provides dialog boxes.ClassesInfoDialog(title, message, *, top=None, left=None, default_css=True, remove_after=None, ok=False)
Displays a dialog box with an information message
from browser.widgets.dialog import InfoDialog # Info box with customized "Ok" button d1 = InfoDialog("Test", "Information message", ok="Got it")from browser.widgets.dialog import InfoDialog # Info box that disappears after 3 seconds d1 = InfoDialog("Test", "Closing in 3 seconds", remove_after=3) EntryDialog(title, message=None, *, top=None, left=None, default_css=True, ok=True)
Displays a dialog box with a prompt message and an entry zone.
When the user hits the "Ok" button or the Entry key inside the entry zone,
an event called "entry" is triggered on the
from browser import bind from browser.widgets.dialog import InfoDialog, EntryDialog d = EntryDialog("Test", "Name") @bind(d, "entry") def entry(ev): value = d.value d.close() InfoDialog("Test", f"Hello, {value} !") Dialog(title, *, top=None, left=None, default_css=True, ok_cancel=False)
Displays a generic dialog box, that can be completed by adding elements to
its attribute
Dialog instances have the following attributes:
from browser import bind, html from browser.widgets.dialog import Dialog, EntryDialog, InfoDialog translations = {'Français': 'Salut', 'Español': 'Hola', 'Italiano': 'Ciao'} d = Dialog("Test", ok_cancel=True) style = dict(textAlign="center", paddingBottom="1em") d.panel <= html.DIV("Name " + html.INPUT(), style=style) d.panel <= html.DIV("Language " + html.SELECT(html.OPTION(k) for k in translations), style=style) # Event handler for "Ok" button @bind(d.ok_button, "click") def ok(ev): """InfoDialog with text depending on user entry, at the same position as the original box.""" language = d.select_one("SELECT").value prompt = translations[language] name = d.select_one("INPUT").value left, top = d.scrolled_left, d.scrolled_top d.close() d3 = InfoDialog("Test", f"{prompt}, {name} !", left=left, top=top) CSS StyleIf the argument default_css passed to the menu isTrue , the following
style sheet is inserted in the current HTML page:
To customize dialog boxes, set default_css to:root { --brython-dialog-font-family: Arial; --brython-dialog-font-size: 100%; --brython-dialog-bgcolor: #fff; --brython-dialog-border-color: #000; --brython-dialog-title-bgcolor: CadetBlue; --brython-dialog-title-color: #fff; --brython-dialog-close-bgcolor: #fff; --brython-dialog-close-color: #000; } .brython-dialog-main { font-family: var(--brython-dialog-font-family); font-size: var(--brython-dialog-font-size); background-color: var(--brython-dialog-bgcolor); left: 10px; top: 10px; border-style: solid; border-color: var(--brython-dialog-border-color); border-width: 1px; z-index: 10; } .brython-dialog-title { background-color: var(--brython-dialog-title-bgcolor); color: var(--brython-dialog-title-color); border-style: solid; border-color: var(--brython-dialog-border-color); border-width: 0px 0px 1px 0px; padding: 0.4em; cursor: default; } .brython-dialog-close { float: right; background-color: var(--brython-dialog-close-bgcolor); color: var(--brython-dialog-close-color); cursor: default; padding: 0.1em; } .brython-dialog-panel { padding: 0.6em; } .brython-dialog-message { padding-right: 0.6em; } .brython-dialog-button { margin: 0.5em; } False and redefine the
CSS classes. The most staightforward is to copy the stylesheet above and edit
it.
Dialog box elements and CSS stylesThe different elements of a dialog box have the following properties and CSS classes:
|