Reputation: 780
I simple run this code in a jupyter notebook/lab cell:
from ipycanvas import Canvas
from ipywidgets import Button
from IPython.display import display
WIDTH = 200 # px
HEIGHT = 200 # px
# Create a canvas 700x250 pixels with a black border
canvas = Canvas(width=WIDTH, height=HEIGHT)
# Add black border around the canvas
canvas.stroke_style = 'black'
canvas.stroke_rect(0, 0, WIDTH, HEIGHT)
# List to store clicked positions
clicked_positions = []
# Function to handle clicks and draw red dots
def handle_click(x, y):
# Add the clicked position to the list
clicked_positions.append((x, y))
# Draw a red dot with radius 3 at the clicked position
canvas.fill_style = 'red'
canvas.fill_circle(x, y, 3)
# Attach the click event handler to the canvas
canvas.on_mouse_down(lambda x, y: handle_click(x, y))
# Button to display clicked positions
show_button = Button(description="Show clicked positions")
# Function to display the clicked positions
def show_positions(b):
print("Clicked positions:", clicked_positions)
show_button.on_click(show_positions)
# Display the canvas and button
display(canvas, show_button)
IT WORKS!
And this is where all the madness starts, so I won't put any of the dozens of issues I experienced in here.
I will just state, that the best outcome, of actually seeing and being able to click onto the canvas within the presentation I only had when installing:
python3.12 -m pip install notebook==6.5.4 ipywidgets==8.1.5 ipycanvas==0.11.0 rise==5.7.1
So in the end it looks like this:
>> python3.12 -m jupyter --version
Selected Jupyter core packages...
IPython : 8.10.0
ipykernel : 6.29.5
ipywidgets : 8.1.5
jupyter_client : 8.6.2
jupyter_core : 5.7.2
jupyter_server : 2.14.2
jupyterlab : not installed
nbclient : 0.10.0
nbconvert : 7.16.4
nbformat : 5.10.4
notebook : 6.5.4
qtconsole : not installed
traitlets : 5.9.0
But also this version crashs after setting a few dots onto the canvas.
ANY HELP is greatly appreciated! Meaning: - I need a canvas, which I can draw on to retrieve the coordinates to the next cell AND I want to do it inside a reveal.js - presentation using jupyter.
If someone has a working version of jupyter notebook/lab using ipywidgets + reaveal.js
and could document its version this would be super helpful, since I already tested a lot of combinations without success -> especially version 4.x.x seem to break a lot of extension codes?! I also wouldn't know for which jupyter version the extension developer created its release eg. ipywidgets?!?
Upvotes: 0
Views: 39