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.menuThis module is made to build a menu, made of an horizontal navigation bar and drop-down submenus. It defines a single class:Menu(container=document.body, default_css=True)
return a menu object
Menu have the following methods:
Menu.add_item(label, callback=None)
add an item to the menu and returns it
Menu.add_link(label, href)
add a link (HTML tag
Menu.add_menu(label)
add a submenu to the current menu and returns it; the submenu is also an
instance of the class
Example
CSS stylingIf the argument default_css passed toMenu() is True (default value),
the following style sheet is inserted in the current HTML page:
To customize the menu, the argument/* Classes for brython.widgets.menu */ :root { --brython-menu-font-family: Arial; --brython-menu-font-size: 100%; --brython-menu-navbar-bgcolor: CadetBlue; --brython-menu-navbar-bgcolor-selected: SkyBlue; --brython-menu-navbar-color: #fff; --brython-menu-color: #000; --brython-menu-submenu-bgcolor: #fff; --brython-menu-submenu-bgcolor-selected: SkyBlue; } /* Items in the main horizontal navigation bar */ .brython-menu-navbar-item { font-family: var(--brython-menu-font-family); font-size: var(--brython-menu-font-size); background-color: var(--brython-menu-navbar-bgcolor); color: var(--brython-menu-navbar-color); padding: 0.5em 1em 0.5em 1em; cursor: default; } .brython-menu-navbar-item:hover { background-color: var(--brython-menu-navbar-bgcolor-selected); } .brython-menu-navbar-item-selected { background-color: var(--brython-menu-navbar-bgcolor-selected); } /* submenu, opened by a click on an item */ .brython-menu-submenu { font-family: var(--brython-menu-font-family); font-size: var(--brython-menu-font-size); background-color: var(--brython-menu-submenu-bgcolor); position: absolute; border-style: solid; border-width: 1px; border-color: var(--brython-menu-color); border-spacing: 0; } /* submenu row */ .brython-menu-submenu-row:hover { color: var(--brython-menu-color); background-color: var(--brython-menu-submenu-bgcolor-selected); } .brython-menu-submenu-row-selected { color: var(--brython-menu-color); background-color: var(--brython-menu-submenu-bgcolor-selected); } /* cell in a submenu row. Each row has two cells, one for the item label, the other one filled with a > if the item has a submenu */ .brython-menu-submenu-item { font-family: var(--brython-menu-font-family); padding: 0.3em 0.3em 0.3em 1em; cursor: default; } /* end of browser.widgets.menu classes */ default_css is set to False and the
menu classes must be redefined. The most straightforward is to copy the
stylesheet above and edit it.
|