THE REFERENCE / 04

Nodecraft Docs

Open Draw Studio

Python / 01

Python: workspace to working app

Choose Open Python counter app in the workspace. It includes a PNG screen plan, connected blocks and Python source. Run loads Python and opens the real counter. Click Add one twice: 0 becomes 2. Reset returns it to 0. The marble Python logo stays in the shared page header.

Follow Describe → Sketch → Blocks → Diagram → Code. The sketch shows the intended heading, number and two buttons; the Python class implements their behavior. The Action block creates matching elements. Build code compiles Start → Create counter & buttons → Report ready → End into the source that Run executes.

Save workspace to keep the whole project privately. Send to Build adds the current sketch and code as one screen. Add a Blank screen called Done, set the counter's Continue to Done, then Assemble app and Run app. Test both buttons and Continue before downloading app.html or saving the app.

from js import document
from pyodide.ffi import create_proxy

class Counter:
    def __init__(self):
        self.value = 0

    def add(self, event):
        self.value += 1
        number.textContent = str(self.value)

    def reset(self, event):
        self.value = 0
        number.textContent = "0"

main = document.createElement("main")
heading = document.createElement("h1")
heading.textContent = "My Python counter"
number = document.createElement("p")
number.id = "count"
number.textContent = "0"
add_button = document.createElement("button")
add_button.textContent = "Add one"
reset_button = document.createElement("button")
reset_button.textContent = "Reset"
for element in [heading, number, add_button, reset_button]:
    main.appendChild(element)
document.body.appendChild(main)
counter = Counter()
callbacks = [create_proxy(counter.add), create_proxy(counter.reset)]
add_button.addEventListener("click", callbacks[0])
reset_button.addEventListener("click", callbacks[1])
Open Python example
  • ↳The sketch is a visual specification, not an image that becomes a working button by itself.
  • ↳Python uses Pyodide's browser bridge to create the page; it is not a hosted Python server.
  • ↳Each Run starts the counter at 0. Saving keeps code and sketch, not the current count.
  • ↳Use the moon icon for dark pages, then Run again to apply the theme to output.
  • ↳Screens are isolated and reset on navigation. Python needs internet to load its runtime.