Skip to main content
# sneakers
A TkInter wrapper for python inspired by the GUI library Shoes for Ruby.

This is intended to make it easier to create simple GUI interfaces quickly. All these classes inheret from their TkInter counterparts so you can use them just as you would their original TkInter counterparts if need be.

To use this library you can star import to get access to all classes and functions;
```python
from sneakers import *
```
How to create windows
--

Context managers are used to create windows, stacks (columns) and flows (rows).

For example, this is how a context manager is used to make a window;

<table>
<tr>
<td align="center">
<b>CODE</b>
</td>
<td align="center">
<b>GUI</b>
</td>
<tr>
<td>
<pre lang="python">
from sandals import *

with window("My window"):
label("Hello world")
</pre>
</td>
<td>
<img src="example_images\\helloworld.png"
alt="Manipulating buttons example">
</td>
</tr>
</table>

The way stacks and flows work was intended to be the same as with the Ruby library Shoes, but it's not quite there yet.
Info on how they're meant to work can be found on the Ruby Shoes website: http://shoesrb.com/

As mentioned below, the library needs to be ideally be rewritten to use TkInter grids, rather than just packing elements in different ways, which is something I'm working on at the moment.
The @button and other GUI decorators
--

Adding the decorator
```python
@button
```
to a function adds a button that triggers that function. The button is located in whatever context manager the function is defined in.


For example, this code will create a window with a button, which when clicked will create a popup;

<table>
<tr>
<td align="center">
<b>CODE</b>
</td>
<td align="center">
<b>GUI</b>
</td>
<tr>
<td valign="top">
<pre lang="python">
from sandals import *

with window():

@button("Create a popup box")
def makePopupBox():
showInfo(message = "You clicked the button")
</pre>
</td>
<td>
<img src="example_images\\buttonexample.png"
alt="Button example">
</td>
</tr>
</table>

Checkboxes, radio buttons, spin boxes, scale bars, and option menus can all be applied as decorators in a similar way. They are also located in whatever context manager (window, stack or flow) the function is defined in.
For example, here is a simple implementation of a check box to change a boolean;

```python
@checkBox("Is the oven on?", checked = True)
def ovenOn(checked):
theOvenIsOn = checked
```

And here is a simple example of how to implement an options menu;

```python
label("How's the oven?")
@optionMenu("clean", "dirty", "broken")
def ovenState(option):
print "The oven is", option
```

All these decorators can also be used as classes where this is more convenient.
Manipulating buttons
---
Because these decorators inherit from their TkInter classes, they can be used as normal (i.e. not as decorators) and then configured using e.g. ```my_button.config(**kwargs)```.

Buttons can be altered even when created as a decorator, as they are added as a function attribute of the function they are applied to, so can be accessed via e.g. ```my_function.button```.

All the TkInter adjectives used to modify buttons - such as ```DISABLE``` and ```NORMAL``` which describe the state of a disabled and enabled button respectively - are imported as well.

Here is an example where this method is used to disable a button created using a decorator;

<table>
<tr>
<td align="center">
<b>CODE</b>
</td>
<td align="center">
<b>GUI</b>
</td>
<tr>
<td valign="top">
<pre lang="python">
from sandals import *

with window():

@button("This button does nothing")
def doNothing():
pass

@button("Disable button")
def disableButton():
doNothing.button.config(state = DISABLED)
</pre>
</td>
<td>
<img src="example_images\\manipulatingbuttonsexample.png"
alt="Manipulating buttons example">
</td>
</tr>
</table>

The @repeat and @loop decorators
---
Two new decorators are included which you might not necessarily associate with a GUI library;
The ``@repeat`` and ``@loop`` decorators.

These create a thread that repeats or loops the function the decorator is applied to. Once the context the decorated function is defined in is destroyed (e.g. closing a window) then that thread is stopped and the function will stop repeating or looping. As an example, here is a function that repeats once a minute;

```python
@repeat(60)
def clock():
print "A minute has passed"
```

The repeat and loop decorators are inspired by similar methods in Shoes, which turn out to be more useful than you might expect when designing a GUI.

Changing and reading text in GUI elements
--

How the text in labels and other GUI elements is changed to try and make them easier to work with.

A slightly more complex example that demonstrates this;

<table>
<tr>
<td align="center">
<b>CODE</b>
</td>
<td align="center">
<b>GUI</b>
</td>
<tr>
<td>
<pre lang="python">
from sandals import *
with window("This is a window"):
label("This is a label",
font = "Verdana 24 bold underline")
with stack(padx=10):
myLabel = label("This text changes")
@button("Change the above text",
font = "Veranda 12 italic")
def change_that_text():
myLabel.text = "OMG it changed"
with flow(pady=10):
edit = editBox("edit me")
@button("<-read edit box")
def read_edit_box():
showInfo(message
= "Edit box says: "
+ edit.text)
</pre>
</td>
<td>
<img src="example_images\\simpleexample.png"
alt="Simple example">
</td>
</tr>
</table>
Complete example
--

`example.py` has a more complete example of how to use the different methods, context managers, etc. which should look like this;

<table>
<tr>
<td align="center">
<b>GUI</b>
</td>
</tr>
<tr>
<td>
<img src="example_images\\example.png"
alt="Complex example">
</td>
</tr>
</table>


# TO DO LIST
- Add to pip.
- Add support for ttk
- Rewrite to use tkinter grids as well as pack.
- Retools this readme.
- Add attribution from previous repositories.


Metadata

Release files for sneakers 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sneakers 0.0.1
File Size Uploaded Provenance
sneakers-0.0.1.tar.gz 11.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sneakers 0.0.1
File Interpreter ABI Platform
sneakers-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / sneakers-0.0.1.tar.gz

Download URL sneakers-0.0.1.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e1b715c8595c492816d64979ac3b4347d58c228b96eb822455bfc23b8a4eff8e
BLAKE2b-256 checksum
How to use checksums
00271d970b72bb4ef829990ae741b4de2702f52a86af3ed669a103a3c1196d19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / sneakers-0.0.1-py3-none-any.whl

Download URL sneakers-0.0.1-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e61eb4dade4807308746246a21fd10f2c16c0e785567667f0caa893651507cf
BLAKE2b-256 checksum
How to use checksums
abccd686595862f11bb60bf3f54e8035fa0f6b9a69a78202e7a9e837d212289c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for sneakers 0.0.1

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page