tVector Home Page


WTF is 'tVector'?

tVector is a convenience wrapper for Tkinter, that supports you in writing code that's vastly shorter, more understandable, and more easily maintainable than using the Tkinter methods directly.

Logically, tVector gives you an alternate geometry paradigm to the existing 'Pack' and 'Grid' geometry managers.

It lets you lay out any window (or subwindow) as a set of 'vectors' - rows and columns of widgets.

Example:

To make it clear, let me walk you through a simple example now:

Example screenshot

Here's the entire example code.

Note that tCol and tRow create a column and a row of widgets respectively.
Any widgets to be included get passed as calls to tW ( a function which returns widget specs as a dict, but you don't need to know this).
Below, we're just using standard Tkinter widgets like Label,Checkbutton,Button and Entry.
As you'll see, it's arranged as a column. Within the column, we have a label, then a checkbutton, then a row of 3 buttons, then a row of 2 entry fields.

    from Tkinter import *
    from tVector import *
   
    class mywin:
        """ A class which implements the functionality for a tVector-created window"""
        def __init__(self, parent):

            # Here's the whole window layout in 7 lines! :)
            self.layout = tCol(tW(Label, 'L1', text="Window Heading", font="helvetica 16 bold"),
                              tW(Checkbutton, 'Chk1', text="A checkbutton"),
                              tRow(tW(Button, 'but1', text="Button 1", command=self.on_button1),
                                   tW(Button, 'but2', text="Button 2", command=self.on_button2),
                                   tW(Button, 'but3', text="Button 3", command=self.on_button3)),
                              tRow(tW(Entry, 'fld1', text="field 1"),
                                   tW(Entry, 'fld2', text="field 2")))

            # Call the 'tBuild' method to actually create and pack the widgets
            self.layout.tBuild(parent)
   
        def on_button1(self):
            print "clicked button1"
            # change the label on button 1
            self.layout.wid('but1', text="New Button1 label")
   
        def on_button2(self):
            print "clicked button2"
            self.layout.wid('but1', text='Button 1')
   
        def on_button3(self):
            print "clicked button3"
   
        def mainloop(self):
            self.layout.mainloop()

    if __name__ == '__main__':

        root = Tk()
        app = mywin(root)
        app.mainloop()

Like what you see?

Why not grab a copy now?

Have phun!

Privacy Policy