Skip to content

pyscript/ltk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ltk

LTK is a little toolkit for writing UIs in PyScript

LTK is implemented as a declarative Python library and leverages jQuery for DOM operations.

Widget Specification

New widget types are created by symply subclassing ltk.Widget:

class HBox(Widget):
    classes = [ "ltk-hbox" ]

By default, widgets are created as div DOM elements. You can choose a different tag:

class Preformatted(Widget):
    classes = [ "ltk-pre" ]
    tag = "pre"

Creating a UI

To create a UI, elements are constructed declaratively:

ltk.Table(
    ltk.TableRow(
        ltk.TableHeader("header1")
        ltk.TableHeader("header2")
    ),
    [
        ltk.TableRow(
            ltk.TableData(value1),
            ltk.TableData(value2),
        )
        for value1, value2 in data
    ],
)

Widgets are added to others by using jQuery's append and appendTo calls:

ltk.body.append(
    ltk.Table(...)
)

container = ltk.VBox(...)
ltk.H1("This is a header").appendTo(container)

Styling

Widgets can be styled using element styles:

ltk.Text("Some text")
    .css("background-color", "red")
    .css("color", "white")
    .css("padding", 8)

Widgets can also be styled using an external stylesheet:

ltk.Text("Some text").addClass("my-special-text)
.ltk-text {
    font-family: Arial;
}

.my-special-text {
    font-family: Courier;
    background-color: red;
    color: white;
    padding: 8px;
}

Events

Event handlers are attached using jQuery mechanisms. As the functions cross PyOdide and JavaScript namespaces, they need to be wrapped with pyodide.ffi.create_proxy calls. We use the shortcut offered by ltk.proxy:

def buy(event):
    purchase(...)

Card("Buy Now").on("click", ltk.proxy(buy))

Examples

See the LTK Kitchen Sink or explore the examples folder

License

LTK is covered under the Apache License:

  • The Apache license is a permissive open source software license.

  • It allows users to freely use, modify, and distribute the software (including for commercial purposes).

  • Modified versions can be distributed without having to release the source code. Though source code changes should be documented.

  • The license requires modified versions to retain the Apache license and copyright notice.

  • The software is provided by the authors "as is" with no warranties.

  • Users are not granted patent rights by contributors, but contributors cannot revoke patent grants for previous contributions.

  • The license does not require derived works to adopt the Apache license. Though this is encouraged for consistency.

About

Write browser apps entirely in Python

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •