TkLayoutpackage simplifies creation of the visual layout of a Tkinter GUI, the
TkPanepackage simplifies the creation, use, and re-use of Tkinter widgets and groups of Tkinter widgets, particularly those that are used to collect or manage data, and that need to interact with other components of the GUI.
TkPanepackage provides a
TkPaneclass that can be subclassed to create custom 'pane' objects. Several general-purpose panes are provided in the
tkpane.libmodule. Pane objects are completely stand-alone, with no inherent dependencies on any other components of the GUI. Pane objects have a standard set of methods, however, by which other panes (or other application code) can enable or disable those panes, or clear their displays. Pane objects also have internal lists of callback functions that are automatically executed when their data are changed to become valid, when their data are changed to become invalid, or when the user leaves the pane (via a keyboard focus change or a mouse movement). Dependencies between panes are easily established with the
requires()method. For example, the statement
ensures that the
run_button_panepane will be disabled when the
input_file_panepane contains invalid data, and will be enabled when the
input_file_panepane contains valid data. When one pane enables another, the first pane passes its own data to the second pane.
The type of inter-pane interaction that is enabled by the
requires()method may be all that is needed in many cases. If more complex interactions are required, however, callback lists can be modified directly to enable other types of inter-pane activation and data sharing.
When a pane object is instantiated, the constructor method (
__init()__) must be passed the Tkinter widget within which the frame will be embedded. Typically that parent widget is a frame. This required argument of pane constructors is identical to the argument that must be passed to the 'build' functions of
TkPaneobjects work together very well, and the combination of the two practically eliminates all of the fiddling with visual and functional aspects of a GUI when using Tkinter directly.
The following example shows how these two packages can be used together to easily build a Tkinter GUI interface by populating layout elements with panes. This example uses pane classes from
This code produces a GUI with the initial appearance shown below. The background of the output directory entry is automatically colored to indicate that it is required but does not contain valid data.
As this example illustrates, the re-usability of pane classes allows Tkinter GUIs to be created with almost no Tkinter code.
TkPanepackage can be downloaded from the Python Package Index (PyPI), or installed with pip.
The documentation for
TkPaneis available on ReadTheDocs.