[Tkinter-discuss] Tix Grid question, was: Re: Is this the right place for Tix questions?

ALAN GAULD alan.gauld at btinternet.com
Mon Apr 21 17:26:26 CEST 2014


>> I don't see a separate Tix group so is this a valid place
>> to ask Tix questions? 
>            .
>YES.


Good. I've been trying to convert some of the Tix examples in the Tcl/Tk 
in a Ntshell O'Reilly book to Tkinter/Tix.

The Tcl version works fine but the Python version gives an error although 
it does display but without any grid/border formatting. The error I get is:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.2/tkinter/__init__.py", line 1402, in __call__
    return self.func(*args)
  File "tixgrid-test.py", line 10, in simpleFormat
    grd.format('grid', x1,y1,x2,y2, anchor='se', fill=0, relief='raised',
  File "/usr/lib/python3.2/tkinter/tix.py", line 341, in __getattr__
    raise AttributeError(name)
AttributeError: format


The code is pretty much a straight translation of the Tcl from the book.:

import tkinter.tix as tix
top = tix.Tk()


def simpleFormat(area, x1, y1, x2, y2):
    print(area,x1,y1,x2,y2)     # see debug output below...
    if area == 'main':
       grd.format('grid', x1,y1,x2,y2, anchor='se', fill=0, relief='raised', 
                  bd=1, bordercolor='gray20')
    elif area in ["x-margin", "y-margin", "s-margin"]:
       grd.format('border', x1,y1,x2,y2, fill=0, relief='raised', 
                  bd=1, bordercolor='gray65')
       
grd = tix.Grid(top, height=10, width=10)
grd.config(formatcmd=simpleFormat)
for x in range(10):
    grd.size_column(x, size='auto')
    for y in range(10):
        grd.set(x,y, itemtype='text', text="({},{})".format(x,y))

grd.size_column(0,size='10char')
grd.pack(expand=True, fill='both')

top.mainloop()

The print() debug output looks like:

y-margin 0 1 0 9
s-margin 0 0 0 0
main 1 1 9 9

and so on.

It looks as if the format command is not recognised. I notice the docs 
say it should only be called from the formatcmd function but that's 
what I'm doing...

Any pointers appreciated. And if anyone knows a decent book or 
web site for Python Tix that would also be much appreciated. 
I can get most things to work in Tix but the Grid has me beat 
so far.

Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos


More information about the Tkinter-discuss mailing list