How to access the output of a script via JS?


I’d like to ask how can one access the output of a script (example: user runs custom code on a py-repl tag and it provides the output on screen). How is it possible to grab this output as a JS variable?


1 Like

Interesting, with pyscript to use js var we can

from js import foo

if its the otherway around maybe we could use pyodide proxy.toJS?
Still learning pyscript ways…
Maybe others know how?

Could you please provide an example of passing a js variable onto a pyscript tag?

<h1 id="example"></h1>
<script> = 'Hello There';
<py-script output="example">
from js import foo

Thank you! And what if I only want the script to run after the user has pressed a button for instance?

well just add event-listener or put it under py-button
(Correct me if im wrong though, this is based on the examples provided in the repo)

Do this()

Update 1:
Please declare the function before calling the event from py-button


<h2 id="bipbop"></h2>
bipped = Element("bipbop")

def click_event(*ags, **kwgs):
    bipped.element.innerText += "Biopsy"

<py-button id="new-task-btn" label="Add Biopsy!">
          def on_click(evt):

Thanks! However, in case I want to add just a print statement inside click_event, it doesn’t appear on the screen. Do you know what may be a solution for that?

Well I suggest for now dont use print.

The function that i gave above is basically the same intention to print and appear on screen.
We have to grab the Element, and add a “string” or variable to that element

foo.element.innerText += “Text”

This will add the Text and appear it on screen