Skip to main content

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:


from Tkinter import Tk, Frame, Label, Listbox, Button, mainloop

tkroot = Tk()
frame = Frame(tkroot)
board_frame = Frame(frame)
for board_name in ["Todo", "Doing", "Done"]:
    inner_frame = Frame(board_frame)
    label = Label(inner_frame, text=board_name)
    listbox = Listbox(inner_frame)
buttons_frame = Frame(frame)
add_button = Button(buttons_frame, text='Add item', command=add)
remove_button = Button(buttons_frame, text='Remove item', command=remove)



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), ])])])



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 a Tkinter.Entry set the initial text.
  • on_*= sets an event callback (and _ is replaced by -). So passing on_Button_3=func is the same as running elem.bind('<Button-3>', func) after creation.
  • set_*= sets attribute values after creation. For example set_title=['title'] has the same effect as title='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 (think id 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.

  • removes some of the less used features like code generation.
  • 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

Download files

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

Files for uielem, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size uielem-0.2.2-py2-none-any.whl (2.5 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size uielem-0.2.2.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page