***************************************************************** Dynamic Building Interfaces (:code:`witkets.tkbuilder.TkBuilder`) ***************************************************************** .. TODO: Include pictures of GUIs designed with TkBuilder (with new widgets!) .. role:: xml(code) :language: xml Purpose ======= This class is responsible for constructing Tk user interfaces based on XML descriptions. It is somewhat similar to GtkBuilder, but without Glade (yet). Basic Usage =========== Consider the following XML string: **demo2.xml** .. literalinclude :: workspace/demo2/demo2.xml :language: xml It describes children of a given Tk container (root element). For instance, when building the interface, :code:`TkBuilder` will insert a label, which can be accessed later by the identifier *lbl1*. This label will have the text property set to *Cap. Kirk* and its background property set to *red*. In fact, for a given object :code:`obj`, most of the XML attributes (the *wid* being an exception) are treated just like this: .. code-block:: python obj[attrName] = attrValue The special (and required) *wid* attribute is used for retrieving objects from the builder once the GUI has been constructed. The special *geometry* tag is used to define the GUI layout based on the Tk geometry managers: pack, grid and place. The *geometry* tag must appear after the definition of all its referenced widgets, just like the example above. In other words, it probably should be the last child of a given container. The Python snippet below should just build the interface described by **demo1.xml** into the main Tk frame: **demo2.py** .. literalinclude :: workspace/demo2/demo2.py :language: python The builded GUI is shown below: .. figure:: img/tkbuilder_example.png :scale: 100 Accessing the Widgets ===================== After building the interface, you can access each widget with the nodes attribute: .. code:: python label = builder['nodes']['lbl1'] print(label['text']) # Cap. Kirk Recognized Tags and Attributes ============================== Although the :func:`~witkets.TkBuilder.add_tag` method can be used to define a new tag and its corresponding class, TkBuilder comes with the following builtin tags: Widgets ------- * :xml:`` * :xml:`