Skip to content

Instantly share code, notes, and snippets.

@pkubik
Created December 29, 2024 16:30
Show Gist options
  • Save pkubik/e0c1e21d8464a2f9410592afbfae6287 to your computer and use it in GitHub Desktop.
Save pkubik/e0c1e21d8464a2f9410592afbfae6287 to your computer and use it in GitHub Desktop.
Minimal image view in NiceGUI
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