Created
December 29, 2024 16:30
-
-
Save pkubik/e0c1e21d8464a2f9410592afbfae6287 to your computer and use it in GitHub Desktop.
Minimal image view in NiceGUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from nicegui import events, ui | |
def mouse_handler(e: events.MouseEventArguments): | |
color = "SkyBlue" if e.type == "mousedown" else "SteelBlue" | |
ii.content += f'<circle cx="{e.image_x}" cy="{e.image_y}" r="15" fill="none" stroke="{color}" stroke-width="4" />' | |
ui.notify(f"{e.type} at ({e.image_x:.1f}, {e.image_y:.1f})") | |
src = "https://picsum.photos/id/565/640/360" | |
with ui.row().classes("w-full border"): | |
ui.label("Left") | |
ui.space() | |
ui.label("Right") | |
with ui.row().classes("w-full border"): | |
ui.space() | |
ii = ( | |
ui.interactive_image( | |
src, | |
on_mouse=mouse_handler, | |
events=["mousedown", "mouseup"], | |
cross=True, | |
) | |
) | |
ui.space() | |
ui.run(reload=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment