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 |
ProblemShow information when the mouse is over an area of the imageSolutionWe will use theonmouseover atribute of the area HTML tag. A text will be
shown on screen depending on the position of the mouse :
from browser import document, html def writetext(txt): # write text in the description zone (white on red) document["description"].text = txt coords = [ (0, 0, 160, 95), (180, 0, 400, 165), (0, 120, 180, 400), (175, 235, 270, 400) ] messages = ["This plane was flying to wonderland in a sunny day", "The Sun and the gas giant planets like Jupiter are by far the largest \ objects in our Solar System.", "This is me or you.", "Dennis the menace!!!!!!!!"] prompt = "Mouse over the items in the image to see the different \ descriptions." writetext(prompt) for coord, msg in zip(coords, messages): # define areas in the image area = html.AREA(shape="rect", coords=coord) # define actions when mouse moves over or out of the area area.bind('mouseover', lambda ev, msg=msg:writetext(msg)) area.bind('mouseout', lambda ev:writetext(prompt)) document["familymap"] <= area |