As I have shared previously, I have worked for many years with Microsoft Access, using it both at home and at work for tracking just about everything in tables linked together in queries and forms. At home I was able to put together a (sort of) application for tracking our finances and inventory. The core of this app is a form that displays transactions and includes text and combo boxes for entering criteria for sorting, filtering and totaling, like this:
I can view transactions by bank account, expense category, month, year, and so on. I can also enter transactions using this same form. Such functionality is a no-brainer in Microsoft Access. Behind all the boxes are string variables that are assembled together to create a SQL statement that gets me what I want to see from the data. Sorting and filtering lists of stuff like is 90% of what do in Access both at home and at work.
My primary goal in Python coding is to reproduce something like the above, using Python code, a GUI tool such as Tkinter and a SQLite database. If I could discover the secret of doing this, the possibilities for data-centric app building would become endless for me. To use a truly Pythonic analogy, this is my own, personal Holy Grail of coding. I only hope my quest meets with better success than poor King Arthur, Sir Robin and the gang…
So off I went into Google-land, almost hearing the cloppety-clop of those coconuts following close behind me, and after many dead ends, false starts and Frenchmen farting in my general direction, I beheld this:
But..how do I get it to work?
First thing I noticed: It appears to require an add-on called “pmw,” which I later found out stands for Python Mega Widgets. Sounds like an appropriately awesome name for an appropriately awesome add on, yes?
(Attention gamers: believe it or not, as I was writing this I accidentally typed “pwn” instead of “pmw!” As in, “I hope I don’t get pwnd by pmw!”)
Pmw seemed to install easily with the good old command line: python setup.py install. This time I didn’t have to summon ez_install or pip. I’m starting to think of those two as my own personal goons, ready to beat up on uncooperative toolkits who refuse to install when I ask them politely with setup.py. “Oh, so you don’t want to install, eh? We have ways of MAKING you install….”
I have learned that whenever I install a new toolkit like this, I can immediately find out if it installed correctly, right from a Python command prompt, like so:
>>> import Pmw
Success! Ah, the delightful silence of a “>>>” prompt, without lines of angry red text! Now, to copy, paste, and run. Oops..no go…got an error: ‘Table’ is not defined.” Well, obviously something is missing here, obviously. Better Google the exact name of the table thingy from the above link: “PmwContribD.” OK, now I see the ‘Table’ is part of another set of widgets called “PmwContribD”, that’s based on the set of widgets (“pmw”) that I just installed. No problem. Found it: http://ostatic.com/pmwcontribd. Thankfully, another hassle-free install. Next, I need to make sure I include the correct “import” statements in my code. According to the PmwContribD documentation for the ‘Table’ widget, they should be these. So I add these statements, and past in the code from the first link above:
from Tkinter import * import Canvas from CanvasGroup import CanvasGroup import Pmw from ShadowBox import ShadowBox import UserList import math import string self.table = Table(self.interior(), cellpadding=pad, xfreeze=1) self.table.addcolumn( RowLabelColumn( title='', datasource=TestDataSource(), width=50, rowheight=rowheight, cellalignment='se', cellpadding=pad, )) for i in range(10): self.table.addcolumn( Column( title='Col %d' % i, datasource=TestDataSource(base=10**i), #width=50 + (10 * i), width=0, rowheight=rowheight, cellalignment='se', cellpadding=pad, ) ) self.table.pack(fill=Tkinter.BOTH, expand=Tkinter.YES)
So I ran it and…still getting the ‘Table’ is not defined’ error. I am now officially stuck. In looking over the code again, I suspect the problem is in the “self” statements. As I recall what I learned about classes, now that I think of it, shouldn’t there be a “class” definition before a “self?” Such as “class MyTable, or something like that? Perhaps a Python professional is out there laughing his head off at this. Nevertheless, for me, this object remains, for the time being, a mystery. So from know on I will refer to it as “The Silver Mystery Table.” Yes, I know it’s actually grayish, but silver sounds a lot cooler, like a precious, elusive treasure. Or a sword, that has cut me. But that’s OK, because I will be back. I will hone my Tkinter skills and live to fight another day!
Besides, it’s only a flesh wound.