# tkup
tkup is a thin wrapper around standard Tkinter widgets, allowing you to write
code that visually reflects the widget hierarchy. It doesn't try to reinvent
the wheel and just helps you use normal Tkinter in a streamlined way.
Typical Tkinter code is flat, even though it represents a heavily nested
structure, which makes it difficult to quickly read and understand the true
organization of the GUI. You must also explicitly assign each widget's master,
which is error-prone and verbose:
```python
import tkinter as tk
from tkinter import ttk
app = tk.Tk()
app.title = "Demo"
outer_frame = ttk.Frame(app)
outer_frame.grid()
hi_button = ttk.Button(outer_frame, text="hi")
hi_button.grid()
app.mainloop()
```
tkup solves this by using nested with-statements. There are factory functions
for each kind of widget, and you can use them as context managers so that
nested master widgets are automatically assigned. Post-instantiation calls,
like gridding, can be accomplished two ways, most traditionally by naming the
yielded value:
```python
from tkup import GUI
app = GUI()
with app.root() as root:
root.title = "Demo"
with app.frame() as outer_frame:
outer_frame.grid()
with app.button(text="hi") as hi_button:
hi_button.grid()
app.run()
```
However, naming every single widget just to grid it can be tiresome.
Inspired by Kotlin's implicit creation of the `it` variable in lambdas,
the GUI class provides an `it` method which returns the current master widget,
and there is an additional convenience method called `with_it` which returns
the GUI instance and its `it` method for quick assignment to variables:
```python
from tkup import GUI
app, it = GUI().with_it()
with app.root():
it().title = "Demo"
with app.frame():
it().grid()
with app.button(text="hi"):
it().grid()
app.run()
```
tkup prefers themed (ttk) widgets wherever available. If you want to use
classic widgets, or if you want to use a custom subclass of `tkinter.Widget`,
then you can use the GUI `widget` method and pass in the type to instantiate:
```python
import tkinter as tk
from tkup import GUI
app = GUI()
with app.root():
with app.widget(tk.Button, text="foo"):
...
```
## Installation
```
pip install tkup
```
tkup supports Python 3.5 and higher.
Metadata
Release files for tkup 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tkup-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / tkup-1.2.0-py3-none-any.whl
| Download URL | tkup-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ecf7ba600980a98c1a7bab2e97ce83e22d8112b0ea1172d1fe7404bd0e93e3cc
|
|
BLAKE2b-256 checksum How to use checksums |
184feb6461d8de8704771c4284663799b631971efa797495efdf464c091c8ce6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for tkup 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.