Examples ========================= Examples are the main way that I learned about Tkinter and how to write code for building GUI's . Unfortunately, it is hard to find examples. Grayson's book has been an immense help over the years and more recently the pyttk-samples distributed by Guilherme Polo have helped greatly. The official Tcl documentation is pretty much limited to man pages which are of minor assistance in getting started with Tkinter. The `tutorial on the Tcl Developers site `_ only recently included Python code. Much experimentation was required before I was able to see a paned window on my screen or a scrolled directory. There are several interesting examples in the examples subdirectory, a directory browser and vrex. In addition there is complex, which is kind of a gee whiz example. Directory Browser ----------------- This example contains a scrolled treeview widget that displays ones unix directory tree. It is a rework of Polo's example to include folder icons which open and close. Polo's example is Based on `bitwalk's directory browser `_. .. image:: dir-tree.jpg Vrex.py ------- In the past I have used a number of regular expressions in Python and used to great advantage `Visual Regexp `__ in composing and testing those regular expressions and thought that rewriting the program in Python would be interesting because * It would illustrate important capabilities of PAGE. * It would be a useful program in its own right. Indeed, I use it all the time. * The original version was written in Tcl/Tk and so uses the regular expression processing of Tcl which is bound to be slightly different from that in Python. So an all Python version using the Python regular expression processing would be true to Python. * The original program had ZERO documentation. I never could figure out all of the facilities present. (The most recent version has one page of documentation.) I wanted a version that I could document. * This example illustrates several point about PAGE support: Building menus, using paned windows, text colorization, synchronization between two scrolled text windows, and a project utilizing two windows. .. image:: Vrex_for_Python.png The main portion of the GUI is a three pain window for entering the regular expression and sample in the first two and the third pane presents match results based on the selection of buttons at the bottom. Operation ````````` Briefly, Vrex works as follows: One enters the regular expression under test into the top text box, and the sample which is the subject of the regular expression match into the middle text box. One may use the File menu to load files into the text boxes, one may directly type entries or use the normal cut and paste facilities of the operating system. The user can also save the regular expression and sample using the File menu. * Pressing the Go button causes the match to be attempted. Also, colorization is applied to both the regular expression and to the sample. The regular expression is colorized to show the portions of the regular expression are to extracted individually. And if the match is successful the corresponding portions of the sample are displayed in the same colors. * By selecting one of the row of buttons marked match, 1, 2, ..., 9, the portions of the sample corresponding to extracted subpatterns are displayed in the match window. * You can use the File menu to load to save both the regular expression and the sample. * The Quit Button terminates the program. * The File menu also has a Quit entry that terminates the program. * The Help menu opens a second GUI containing a ScrolledText widget which has help information. The regular expression should be colorized showing the portions to be extracted in different colors and as well as the matching portion of the sample. If you then Select Match, that matching portion of the sample will be shown in the Match text box. Select 1, and the portion matching the sub expression will be shown, etc.. You can also load a file into the sample window and thus run the regular expression against many strings. Exploration ``````````` vrex is composed of two modules vrex.py which is the main GUI and vrex_help.py. The main GUI is made up of a menu a paned window with three adjustable sub-windows each of which contains a scrolled test window and a row of buttons which control the action of the program. The GUI may be resized as may the help window. It illustrates putting scrolled text boxes into panes of a paned window. I also show how to synchronize scrolled text boxes so that selecting a line in one paned window with Button-1 will cause the corresponding line to be visible in the other window. For the subpattern buttons in the GUI, I used Button widgets rather than TButton widgets because I wanted the labels to match the colors of the regular expression grouping and the corresponding match strings. In addition, I wanted larger fonts than the default. I changed the colors of the Button backgrounds with the Attribute Editor. In the examples/vrex subdirectory there are two files v.tcl and v_help.tcl which can be separately specified as parameters to page and used to build the initial version of v.py and v_help.py. These are executable programs which don't really do anything other than show the GUI. One then needs to fill them in with the code that provides the function of the application and links the two GUI's together. I have called them v.tcl rather than vrex.tcl, otherwise generating Python from them would over write the completed example. After firing up vrex.py, try dragging the corner to see how well the relative placement works. Progress Bar ------------ This example shows the usage of the progress bar widget but is included mainly for illustrating an application with two top level windows. It shows how the main window is able to interact with variables and procedures in the imported module which actually displays the progress bar. Complex ------- This really isn't much of an example doing nothing but does showing nesting of a paned window inside of a paned window and a notebook widget nested inside of a paned window. By the way, one can enlarge the top level window and copy and paste the whole paned window to a new location. Menu.py ------- This just portrays a fairly extreme menu bar example. Note, I do not advocate this as a style to be used; it merely suggests some of the things that can be done. While this example works as expected on my Linux Mint 13 machine, it does not work as well on my XP machine. The way it was conceived, there is a small image to the right of the label in the left of the menu bar. However, on XP neither the label nor the image is shown. What one gets is "(image)". Strange since if you go down sever levels there is an image to the left of one of the check buttons. I think that is a problem with Tk. standard.tcl ------------ This is just a top level window with each of the standard tk widgets that I support. It just shows that I can generate working Python code for each. The lowercase 's' emphasizes that it doesn't do much. themed.tcl ---------- As above for the themed widgets.