1. Introduction

Witkets is a collection of extensions for tkinter and ttk, featuring:

  • a XML-based GUI builder,

  • INI-based stylesheets,

  • an application helper class (witkets.Application)

  • many new widgets, ranging from LEDs and LogicSwitches to Tanks, Scopes, Ribbon toolbars and a text view with Python syntax highlighting.

For effective usage of this library, prior knowledge of tkinter basics is required.

1.1. Acquiring and Installing witkets

1.1.1. Requirements

  • Python 3.6+

  • tkinter module

  • pygments (optional; used in text widgets syntax highlighting)

1.1.2. Install by PyPI

The easiest way to install witkets is by using pip package manager.

Just run, as administrator:

# pip3 install witkets

On Windows platforms that might be:

# pip install witkets

In some Linux distributions the package is called python3-pip. On Windows platforms the pip3 binary is usually named pip.

1.1.3. Installing from the Latest Source Code

This package is hosted at BitBucket and its latest version can be retrieved with:

git clone https://bitbucket.org/leandromattioli/witkets.git

It uses the standard Python installation script. You can install it with:

# python3 setup.py install

1.2. Overview of witkets

1.3. Demo 1

Consider the following GUI application:

_images/witkets_themed.png

With this library, you can use XML markup to describe the elements and the layout of the interface and then use a builder to construct and place the widgets.

The source-code for this demo is given below:

demo1.xml

<?xml version="1.0"?>
<root borderwidth='5'>
    <style>
	    [White.TLabelframe]
	    borderwidth=3
	    [White.TLabelframe.Label]
	  </style>

    <!--First Frame-->
    <labelframe wid="frm1" text="Some Standard Tk Widgets">
        <button wid="btn1" text="Button" />
        <checkbutton wid="check1" text="Checkbutton!" />
        <entry wid="entry1" text="Entry" />
        <label wid="lbl1" text="Label" />
        <radiobutton wid="radio1" text="RadioButton" />
        <spinbox wid="spin1" from="0" to="255" width="3" />
        <scale wid="scale1" from="0" to="255" />
        <geometry>
            <pack for="btn1" side="left" padx="10" />
            <pack for="check1" side="left" padx="10" />
            <pack for="entry1" side="left" padx="10" />
            <pack for="lbl1" side="left" padx="10" />
            <pack for="radio1" side="left" padx="10" />
            <pack for="spin1" side="left" padx="10" />
            <pack for="scale1" side="left" padx="10" />
        </geometry>
    </labelframe>

    <!--Second frame-->
    <labelframe wid="frm2" text="Other Standard Tk Widgets and Ttk">
        <text wid="text1" height="5" width="30" />
        <message wid="msg1" text="Message:&#10;multiline text!" />
        <!--<listbox wid="list1" height="5" />-->
        <scrolledtext wid="scrolledtext1" height="5" width="40" />
        <geometry>
            <pack for="msg1" side="left" padx="10" />
            <pack for="text1" side="left" padx="10" />
            <!--<pack for="list1" side="left" padx="10" />-->
            <pack for="scrolledtext1" side="left" padx="10" />
        </geometry>
    </labelframe>


    <themedlabelframe wid="frm3" title="Some new widgets (including this frame)">
        <led wid="led1" />
        <logicswitch wid="switch1" />
        <numericlabel wid="numlbl1" />
        <tank wid="tank1" />
        <plot wid="plot1" width="200" height="200" xlabels="/3" 
              labelsformat="(%.0f, %.2f)" xlimits="(0,3)" />
        <scope wid="scope1" width="200" height="200" />
        <geometry>
            <pack for="led1" side="left" padx="10" />
            <pack for="switch1" side="left" padx="10" />
            <pack for="numlbl1" side="left" padx="10" />
            <pack for="tank1" side="left" padx="10" />
            <pack for="plot1" side="left" padx="10" />
            <pack for="scope1" side="left" padx="10" />
        </geometry>
    </themedlabelframe>


    <labelframe wid="frm4">
        <label wid="lbl2" text="Widgets requiring reasonable further coding to be useful" />
        <label wid="lbl3" text="Canvas, ComboBox, PanedWindow, MenuButton, ListBox" />
        <geometry>
            <pack for="lbl2" />
            <pack for="lbl3" />
        </geometry>
    </labelframe>


    <geometry>
        <pack for="frm1" ipadx="10" ipady="10" expand='1' fill='both' />
        <pack for="frm2" ipadx="10" ipady="10" pady='10' expand='1' fill='both' />
        <pack for="frm3" ipadx="10" ipady="10" pady='10' expand='1' fill='both' />
        <pack for="frm4" ipadx="10" ipady="10" expand='1' fill='both' />
    </geometry>

</root>

demo1.py

#!/usr/bin/env python3
import witkets as wtk

class App(wtk.Application):
    def __init__(self):
        wtk.Application.__init__(self, ui_filename='app.xml', title='Demo', 
                                 theme='clam')
        self.root['borderwidth'] = 10    
    # ... user methods for configuring and handling events
    # using self.root (main window) and self.builder (TkBuilder instance)

app = App()
app.run()