{"id":19911653,"url":"https://github.com/pyscript/ltk","last_synced_at":"2025-09-23T21:32:19.287Z","repository":{"id":206799106,"uuid":"712456639","full_name":"pyscript/ltk","owner":"pyscript","description":"LTK is a little toolkit for writing UIs in PyScript","archived":false,"fork":false,"pushed_at":"2024-07-16T09:43:39.000Z","size":4232,"stargazers_count":86,"open_issues_count":4,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-08-06T09:11:45.815Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyscript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-31T14:04:30.000Z","updated_at":"2024-08-08T22:12:23.041Z","dependencies_parsed_at":"2024-01-31T10:27:55.072Z","dependency_job_id":"84bd6cd2-4db1-4f39-a7a3-c89a56c56376","html_url":"https://github.com/pyscript/ltk","commit_stats":null,"previous_names":["laffra/ltk","pyscript/ltk"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyscript%2Fltk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyscript%2Fltk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyscript%2Fltk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyscript%2Fltk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyscript","download_url":"https://codeload.github.com/pyscript/ltk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234003824,"owners_count":18764337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T21:26:09.798Z","updated_at":"2025-09-23T21:32:19.281Z","avatar_url":"https://github.com/pyscript.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ltk\nLTK is a little toolkit for writing web UIs in PyScript. For an explanation of PyScript and LTK, see [YouTube](https://www.youtube.com/watch?v=5nseG-iU62g\u0026list=PLGVZCDnMOq0qkbJjIfppGO44yhDV2i4gR\u0026index=6).\n\nFor examples, see:\n\n - The [LTK kitchensink](https://pyscript.github.io/ltk/) for a live demo of all the widgets.\n - [Lifesaver.coach](https://lifesaver.coach/), a modern, responsive app written in LTK.\n - [PyAlgoViz](https://github.com/laffra/pyalgoviz-pyscript) using MicroPython, PyOdide, and Reactive LTK.\n - A [Todo App](https://github.com/laffra/todo) that showcases declarative UIs using Reactive LTK and calling OpenAI.\n - A [Slides Player](https://github.com/laffra/slides) that downloads a Google Slides presentation and shows it with LTK.\n - Why use LTK? See the [pitch](https://pyscript.github.io/ltk/?tab=9), written with LTK.\n - A personal website, [chrislaffra.com](https://chrislaffra.com), that uses several animations, SVG, styling, and timers to render a visual resume.\n - An animated [Holiday card](https://laffra.pyscriptapps.com/merry-christmas/latest/) where PyScript logo tree ornaments are animated using Python code in the browser using LTK.\n - [PySheets](https://pysheets.app), a spreadsheet written in Python, using LTK.\n   \nLTK is implemented as a declarative Python library and leverages `jQuery` for DOM operations.\n\n## Installing LTK\n\nInstall LTK from pypi:\n```\npython3 -m pip install pyscript-ltk\n```\n## Hello World\n\n```python\nimport ltk\n\nltk.Text(\"Hello World\").appendTo(ltk.body)\n```\n\n## Getting Started\n\nTo get started with LTK, we recommend you try it out on pyscript.com:\n -  [Minimal LTK with MicroPython](https://pyscript.com/@laffra/ltk-on-micropython/latest)\n -  [Minimal LTK with PyOdide](https://pyscript.com/@laffra/ltk-on-pyodide/latest)\n\n## Widget Specification\n\nNew widget types are created by subclassing `ltk.Widget`:\n\n```python\nclass HBox(Widget):\n    classes = [ \"ltk-hbox\" ]\n```\n\nBy default, widgets are created as `div` DOM elements. You can choose a different tag:\n\n```python\nclass Preformatted(Widget):\n    classes = [ \"ltk-pre\" ]\n    tag = \"pre\"\n```\n\n## Creating a UI \n\nTo create a UI, elements are constructed declaratively:\n\n```python\nltk.Table(\n    ltk.TableRow(\n        ltk.TableHeader(\"header1\")\n        ltk.TableHeader(\"header2\")\n    ),\n    [\n        ltk.TableRow(\n            ltk.TableData(value1),\n            ltk.TableData(value2),\n        )\n        for value1, value2 in data\n    ],\n)\n```\n\nWidgets are added to others by using `jQuery`'s `append` and `appendTo` calls:\n```python\nltk.body.append(\n    ltk.Table(...).element\n)\n\ncontainer = ltk.VBox(...)\nltk.H1(\"This is a header\").appendTo(container)\n```\n\nWhen an LTK widget is created, a corresponding jQuery element is attached to it in \nthe `ltk.Widget.__init__` constructor. It uses the `tag` value defined by the \ndeclaring class and the constructed element is referred to as `element`.\nAs the `append` call is a JavaScript function, implemented by jQuery, we do not\npass the LTK widget directly, but pass its `element` to append to the DOM.\n\n## Styling\n\nWidgets can be styled using using three different approaches:\n\n1. Styling with element styles using `jQuery`'s `css` function:\n```python\nltk.Text(\"Error: Flux capacitor low!\")\n    .css(\"background-color\", \"red\")\n    .css(\"color\", \"white\")\n    .css(\"padding\", 8)\n```\n\n2. Styling using a `dict` to make it easier to share styles:\n```python\nerror = {\n    \"background-color\": \"red\",\n    \"color\": \"white\",\n    \"padding\": 8,\n}\nltk.Text(\"Error: Flux capacitor low!\", error)\n```\n\n3. Styling using CSS classes and an external stylesheet, using `jQuery`'s `addClass` function:\n```python\nltk.Text(\"Some text\").addClass(\"my-special-text)\n```\nThe external style sheet should have these rules:\n```css\n.ltk-text {\n    font-family: Arial;\n}\n\n.my-special-text {\n    font-family: Courier;\n    background-color: red;\n    color: white;\n    padding: 8px;\n}\n```\n\nExternal stylesheets can be included in the original `index.html` or injected at runtime from Python using:\n```python\nltk.inject_style(\"https://example.org/awesome_styles.css\")\n```\n\n## Events\n\nEvent handlers are attached using `jQuery` mechanisms. \n```python\ndef buy(event):\n    purchase(...)\n\nltk.Card(\"Buy Now\").on(\"click\", ltk.proxy(buy))\n```\n\nYou can also use the more declarative decorator:\n```python\n@ltk.callback\ndef buy(event):\n    purchase(...)\n\nltk.Card(\"Buy Now\").on(\"click\", buy)\n```\n\n## Examples\n\nSee the [LTK kitchensink](https://pyscript.github.io/ltk/) or explore the `examples` folder\n\n## Applications built using LTK\n\n- [PySheets](https://pysheets.app)\n\n## License\n\nLTK is covered under the Apache License:\n\n - The Apache license is a permissive open source software license.\n\n - It allows users to freely use, modify, and distribute the software (including for commercial purposes).\n\n - Modified versions can be distributed without having to release the source code. Though source code changes should be documented.\n\n - The license requires modified versions to retain the Apache license and copyright notice.\n\n - The software is provided by the authors \"as is\" with no warranties.\n\n - Users are not granted patent rights by contributors, but contributors cannot revoke patent grants for previous contributions.\n\n - The license does not require derived works to adopt the Apache license. Though this is encouraged for consistency.\n\n\n\n## Upload new version to PyPi\n\nIf you never ran setuptools, twine, etc, on your machine do this:\n```console\npython3 -m pip install --user --upgrade setuptools wheel twine build\n```\n\nTo make a build, first increment the version in `pyproject.toml`:\n```python\n[project]\nname = \"pyscript-ltk\"\nversion = \"0.1.22\"\n```\n\nThen build the package into a source distribution and a Python wheel:\n```console\npython3 -m build\n```\n\nThen verify whether the build works for pypi:\n```console\ntwine check dist/*\n```\n\nThen upload to the pypi test environment:\n```console\ntwine upload --repository pypitest dist/*\n```\n\nFinally, if the pypi test upload appears to work fine, run:\n```console\ntwine upload dist/*\n```\n\nOr, as a one-liner:\n```console\nrm dist/* \u0026\u0026 python3 -m build \u0026\u0026 twine upload dist/*\n```\n\nIf you get an error that a certain version already exists, check the contents of the `dist` folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyscript%2Fltk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyscript%2Fltk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyscript%2Fltk/lists"}