





























import ltk
(
ltk.VBox(
ltk.HBox(
ltk.Text("Hello"),
ltk.Button(
"World",
lambda event:
ltk.find(".ltk-button, a")
.css("color", "red")
)
.css("color", "blue")
)
)
.appendTo(ltk.window.document.body)
) (edited).css() stuff, isn't a dot supposed to signify an attribute of something else? (edited)
css is an attribute of a widget. And because we're between parentheses we're allowed to use newlines and tabs this way? So the dot applies to the return values of those widget constructors? Does css() return the widget it was called on?





find() the element you just added?

find() the element you just added? self.thispart = ltk.Input() then you have long term access to it. or give it an id with .attr("id","zoom").addClass("vcenter bloat") and get it whenever you need it with an ltk.find("#zoom").val() or an ltk.find_list(".bloat") or an ltk.jQuery("#zoom") or somesuch. (edited)
my_w = MyWidget().appendTo(document.body)
my_w.text('New Text') (edited)

self.thispart = ltk.Input() then you have long term access to it. or give it an id with .attr("id","zoom").addClass("vcenter bloat") and get it whenever you need it with an ltk.find("#zoom").val() or an ltk.find_list(".bloat") or an ltk.jQuery("#zoom") or somesuch. (edited)













<!-- Import PyScript -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
<!-- Import jQuery - used in ltk/jquery.py -->
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
in body I have:
<script type="py" src="main.py" config="pyscript_pyo.toml" terminal></script>
<link rel="stylesheet" href="./main.css"/>



<!-- Import PyScript -->
<link rel="stylesheet" href="https://pyscript.net/releases/2024.8.2/core.css">
<script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
<!-- Import jQuery - used in ltk/jquery.py -->
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
in body I have:
<script type="py" src="main.py" config="pyscript_pyo.toml" terminal></script>
<link rel="stylesheet" href="./main.css"/> 

type="submit on the button, but for it to work the button and the text box need to be in a form, which was mostly easy to do (change my widget from inheriting from ltk.Div to inheriting ltk.Form) but I had to set action on the form for it to be a valid and functional form. I found the way to what while preventing the form submit from performing a page load is: self.attr("action", "javascript:void(0);") but I was dissatisfied with that because it's js. So on a hunch I changed it to self.attr("action", "pyscript:lambda e:pass") and I was very pleased that this was correct!





remove_notif = ltk.proxy(lambda event, ui: ltk.jQuery(event.target).remove())
with this
for notif in reversed(data.pop("notifications", [])):
ltk.Div(ltk.Text(notif)).attr("id", "notif-popup").on("dialogclose", remove_notif).dialog()
cos clicking the close button on a jQuery dialog doesn't remove it from the DOM and that's not friendly for screenreaders














remove and append calls on the popup (it is a jQuery node). For instance, this adds an item: menu.popup.append(new_item) and this removes the second item: menu.popup.children().eq(1).remove(). See https://github.com/pyscript/ltk/blob/main/ltk/widgets.py#L858 (edited)
1





ltk.Model and enabled ltk.Text and ltk.Input as the first two View widgets that can be connected to a model. See the example in the KitchenSink called "MVC": https://pyscript.github.io/ltk/?tab=14
ltk.LocalStorageModel that automatically saves changes in models into HTML localStorage. That makes creating a Todo app very easy: https://pyscript.com/@laffra/todo-app/latest?files=model.py (edited)
Traceback (most recent call last):
File "/lib/python312.zip/_pyodide/_base.py", line 523, in eval_code
.run(globals, locals)
^^^^^^^^^^^^^^^^^^^^
File "/lib/python312.zip/_pyodide/_base.py", line 357, in run
coroutine = eval(self.code, globals, locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<exec>", line 2, in <module>
File "/lib/python3.12/site-packages/floofbytes/webui/manager.py", line 25, in __init__
self.menu_cont = ltk.Menu("Containers")
^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/ltk/widgets.py", line 860, in __init__
self.label.on("click", proxy(lambda event: self.show(event)))
File "/lib/python3.12/site-packages/ltk/widgets.py", line 314, in on
return self.element.on(events, selector, data, proxy(handler))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "http://localhost/jquery/jquery-3.6.0.js", line 5906, in on
File "http://localhost/jquery/jquery-3.6.0.js", line 5181, in on
File "http://localhost/jquery/jquery-3.6.0.js", line 207, in each
File "http://localhost/jquery/jquery-3.6.0.js", line 385, in each
File "http://localhost/jquery/jquery-3.6.0.js", line 5182, in on/<
File "http://localhost/jquery/jquery-3.6.0.js", line 5266, in add
TypeError: Expected callable





Traceback (most recent call last):
File "/lib/python312.zip/_pyodide/_base.py", line 523, in eval_code
.run(globals, locals)
^^^^^^^^^^^^^^^^^^^^
File "/lib/python312.zip/_pyodide/_base.py", line 357, in run
coroutine = eval(self.code, globals, locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<exec>", line 2, in <module>
File "/lib/python3.12/site-packages/floofbytes/webui/manager.py", line 25, in __init__
self.menu_cont = ltk.Menu("Containers")
^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/ltk/widgets.py", line 860, in __init__
self.label.on("click", proxy(lambda event: self.show(event)))
File "/lib/python3.12/site-packages/ltk/widgets.py", line 314, in on
return self.element.on(events, selector, data, proxy(handler))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "http://localhost/jquery/jquery-3.6.0.js", line 5906, in on
File "http://localhost/jquery/jquery-3.6.0.js", line 5181, in on
File "http://localhost/jquery/jquery-3.6.0.js", line 207, in each
File "http://localhost/jquery/jquery-3.6.0.js", line 385, in each
File "http://localhost/jquery/jquery-3.6.0.js", line 5182, in on/<
File "http://localhost/jquery/jquery-3.6.0.js", line 5266, in add
TypeError: Expected callable 



Traceback (most recent call last):
File "/lib/python312.zip/_pyodide/_base.py", line 523, in eval_code
.run(globals, locals)
^^^^^^^^^^^^^^^^^^^^
File "/lib/python312.zip/_pyodide/_base.py", line 357, in run
coroutine = eval(self.code, globals, locals)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<exec>", line 2, in <module>
File "/lib/python3.12/site-packages/floofbytes/webui/manager.py", line 25, in __init__
self.menu_cont = ltk.Menu("Containers")
^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/ltk/widgets.py", line 860, in __init__
self.label.on("click", proxy(lambda event: self.show(event)))
File "/lib/python3.12/site-packages/ltk/widgets.py", line 314, in on
return self.element.on(events, selector, data, proxy(handler))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "http://localhost/jquery/jquery-3.6.0.js", line 5906, in on
File "http://localhost/jquery/jquery-3.6.0.js", line 5181, in on
File "http://localhost/jquery/jquery-3.6.0.js", line 207, in each
File "http://localhost/jquery/jquery-3.6.0.js", line 385, in each
File "http://localhost/jquery/jquery-3.6.0.js", line 5182, in on/<
File "http://localhost/jquery/jquery-3.6.0.js", line 5266, in add
TypeError: Expected callable 








ltk.window.development_location = "C:/Users/laffr/dev/todo/src" This is great for debugging, iterative development, learning, and explanation of a UI when doing a demo to stakeholders or peers.












ltk.get(), but am constantly getting Cross-Origin Request Blocked: (Reason: CORS header βAccess-Control-Allow-Originβ missing). Status code: 200 errors.
Minimal example showing the error: https://pyscript.com/@doks5/test-url-check/latest?files=main.py
I am clearly doing something wrong, so any hints how to fix the error will be much appreciated
Thanks

ltk.get(), but am constantly getting Cross-Origin Request Blocked: (Reason: CORS header βAccess-Control-Allow-Originβ missing). Status code: 200 errors.
Minimal example showing the error: https://pyscript.com/@doks5/test-url-check/latest?files=main.py
I am clearly doing something wrong, so any hints how to fix the error will be much appreciated
Thanks 






micropython.mjs:1 Aborted(Assertion failed: stringToUTF8Array expects a string (got symbol))
error.js:15 RuntimeError: Aborted(Assertion failed: stringToUTF8Array expects a string (got symbol))
at abort (micropython.mjs:1:14749)
at assert (micropython.mjs:1:9826)
at stringToUTF8Array (micropython.mjs:1:30547)
at stringToUTF8 (micropython.mjs:1:81432)
at stringToUTF8OnStack (micropython.mjs:1:90640)
at string (micropython.mjs:1:90806)
at Object.ccall (micropython.mjs:1:91309)
at Object.get (micropython.mjs:1:112548)
at Proxy.toString (<anonymous>)
at w (jquery.min.js:2:986)
The package versions that the project uses are:
https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css
https://pyscript.net/releases/2025.2.3/core.css
https://pyscript.net/releases/2025.2.3/core.js
https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js
https://cdn.jsdelivr.net/npm/jquery-ui@1.14.1/dist/jquery-ui.min.js
https://cdn.jsdelivr.net/npm/jquery-ui@1.14.1/dist/themes/base/jquery-ui.min.css
Has anyone else observed similar behaviour?
jquery-ui 1.13.2 I have had bugs similar to this where I am not using pyscript.ffi.to_js properly. This kind of error points (I think) to not sending python data back to JS side in proper form. Having said that I also had some difficulty with images, videos and SVG when I was using ltk.Image for example. Try commenting out portions of the UI until it works maybe...


ltk.Paragraph("MicroPython VS Pyodide").appendTo(ltk.window.document.body)
instead of:
ltk.find("body").append(ltk.Paragraph("MicroPython VS Pyodide"))


packages = [ "pyscript-ltk==0.2.20", "fpdf2==2.8.1"] but pdf.js may be much better

pdf.js reads pdfs and my example 'fpdf2' is actually about writing pdfs. So no real comparison. how did you get on

pdf.js reads pdfs and my example 'fpdf2' is actually about writing pdfs. So no real comparison. how did you get on 