Skip to main content
# TkML

Library to build [Tkinter](https://docs.python.org/3/library/tkinter.html)
structures from [YAML](http://yaml.org/) descriptions.

It requires [PyYAML 3.12](http://pyyaml.org/wiki/PyYAML).

## Use

```python
import tkml

...

with open(filename) as fp:
toplevel = tkml.load_fp(fp)
```

There is a fixtures factory too:

```python
import tkml

# With no arguments, it assumes fixtures/ subdirectory neighbor to current script
loader = tkml.fixtures()
toplevel = loader('my-app.yaml')
```

### API

`tkml.load_fp()`:

- `fp: io.TextBase`: file pointer to YAML file
- `master: tkinter.Misc`: parent widget
- `use_tix: bool`: use or not `tix` – defaults to false
- `context`: context to `ctx[]`, `argparse.Namespace`,
`collections.namedtuple`, or `dict`
- returns the toplevel widget

`tkml.fixtures()`:

- `origin: str`: the directory containing the YAML files, defaults to
subdirectory `fixtures/` neighbor to the script calling the factory
- returns the loader function

Loader function returned by `tkml.fixtures()`:

- `fixture: str`: YAML file name under fixtures directory
- `master: tkinter.Misc`: parent widget
- `use_tix: bool`: use or not `tix` – defaults to false
- `context`: context to `ctx[]`, `argparse.Namespace`,
`collections.namedtuple`, or `dict`
- returns the toplevel widget

## Resource example

```yaml
tk:
children:
- frame:
children:
- frame:
children:
- label:
text: _(word-to-search)
pack:
anchor: nw
side: left
expand: false
- entry:
pack:
anchor: ne
side: right
fill: x
expand: true
bind:
<Return>: ctx[search]
focus: null
pack:
anchor: n
fill: x
expand: true
- button:
text: _(search)
command: ctx[search]
pack:
anchor: s
expand: false
- scrolled-text:
call/set_text:
- ctx[set_text]
- "!self"
wrap: word
pack:
anchor: s
fill: both
expand: true
pack:
fill: both
expand: true

#
# Calls after tree is built:
#

option-add:
- "*tearOff"
- false

# call/* call the CAR (a callable) with CDR as parameters
call/set_entry:
- ctx[set_entry]
- "!frame.!frame.!entry"
```

- `ctx[*]` gets a key from the context.
- `_(*)` is the [`gettext` function](https://docs.python.org/3/library/gettext.html#gettext.gettext).
- `!self` is the current widget.
- `!frame.frame2` is the second frame from inside de first frame at top.

## Copyright

This library is under
[3-Clause BSD License](https://opensource.org/licenses/BSD-3-Clause).

You can read the copying text
[here](https://bitbucket.org/cacilhas/tkml/src/master/LICENSE.txt).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tkml-0.5.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file tkml-0.5.tar.gz.

File metadata

  • Download URL: tkml-0.5.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tkml-0.5.tar.gz
Algorithm Hash digest
SHA256 2f9e2f462c15e6679b45f37cca23c499376837357369917928e94e562ab9d260
MD5 f9c315cb33e67910752d4f8407215f98
BLAKE2b-256 d465a2f2aea4cd150be167799946d819a2240cd34aaf5ed61a215a0b1457e000

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.5 This release

1 file

0.4.1

1 file

0.4

1 file

0.3

1 file

0.2

1 file

0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page