Wrapper over Tkinter for more Pythonic UI building
Project description
uielem - wrapper over Tkinter for more Pythonic UI building
Sometimes you just want to make a quick UI to make some visual task easier and
Tkinter
is a fast UI toolkit that's packaged with Python since forever. uielem
hopes to provide a more modern/Pythonic syntax for using Tkinter
.
A simple example:
Before
from Tkinter import Tk, Frame, Label, Listbox, Button, mainloop
tkroot = Tk()
tkroot.title('Kanban')
frame = Frame(tkroot)
frame.pack()
board_frame = Frame(frame)
board_frame.pack(side='top')
for board_name in ["Todo", "Doing", "Done"]:
inner_frame = Frame(board_frame)
inner_frame.pack(side='left')
label = Label(inner_frame, text=board_name)
label.pack(side='top')
listbox = Listbox(inner_frame)
listbox.pack(side='top')
buttons_frame = Frame(frame)
buttons_frame.pack(side='top')
add_button = Button(buttons_frame, text='Add item', command=add)
add_button.pack(side='left')
remove_button = Button(buttons_frame, text='Remove item', command=remove)
remove_button.pack(side='left')
mainloop()
After
from uielem import UI, uidict
from Tkinter import Tk, Frame, Label, Listbox, Button
uiroot = UI(Tk, name='root', title='Kanban', children=[
UI(Frame, packside='top', children=[
UI(Frame, packside='left', name='boards', children=[
UI(Frame, packside='top', children=[
UI(Label, text=board_name),
UI(Listbox, name=board_name.lower())])
for board_name in ["Todo", "Doing", "Done"]]),
UI(Frame, packside='left', children=[
UI(Button, text='Add item', command=add),
UI(Button, text='Remove item', command=remove), ])])])
uiroot.makeelem()
uidict["root"].mainloop()
Installation
pip install -r requirements.txt
uielem
depends on undoable.
Usage and features
The basic pattern is just UI(<tkinter elem>, <keyword arguments>, children=[<chidren>])
.
Keyword arguments
packside=
sets the packing side for all children (contained in the element).defaulttext=
for aTkinter.Entry
set the initial text.on_*=
sets an event callback (and_
is replaced by-
). So passingon_Button_3=func
is the same as runningelem.bind('<Button-3>', func)
after creation.set_*=
sets attribute values after creation. For exampleset_title=['title']
has the same effect astitle='title'
.- Other non-special keyword arguments are passed through to the Tkinter element.
Other features
uidict
contains all named (name=something
) elements for easy reference. Names must be globally unique (thinkid
in SVG).- To add and remove child elements from a container, treat it like a list (using
.append
,.insert
and.remove
). - Children of the wrapper can be accessed by indexing (such as
uiroot[0][1]
). - The wrapper can access the Tkinter object with the
.elem
attribute and the Tkinter object can access the wrapper with.ui
.
Alternate versions
uielem
is now rather large so two lighter versions of uielem
are provided in the summaries
folder but they may not always be up to date.
simple_uielem.py
removes some of the less used features like code generation.minimal_uielem.py
only works with UIs generated once and never modified after that (like in the example) but is otherwise fully compatible. Also removes the dependency on undoable.
They also serve as documentation for uielem
's architecture/inner workings.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file uielem-0.2.2.tar.gz
.
File metadata
- Download URL: uielem-0.2.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ae2c28ca4d106c56738c3952dc02586b2a62e09d7c4a8a1792b28b211cfdec3 |
|
MD5 | 3dc302ea01bb06b39ec273dd2eb1f4b4 |
|
BLAKE2b-256 | 04e552798d1e63fc260d132421017bc93ebe29a9bdcb0e760cf847065ad10220 |
File details
Details for the file uielem-0.2.2-py2-none-any.whl
.
File metadata
- Download URL: uielem-0.2.2-py2-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c749eff68b10680dd4dc663189ab87c69c5c2b830f937d73d73c16f6f814e70 |
|
MD5 | f2384a20795c18acdc61a5111365add2 |
|
BLAKE2b-256 | ab4ea4940a24cd16a53f403402743bba15776a87fc634efba5e096ab88f2c11c |