Tkinter Unix and Windows incompatibility
see.signature at no.spam
Wed Aug 27 09:57:30 CEST 2008
On Wed, 27 Aug 2008 06:50:30 +0200, akineko <akineko at gmail.com> wrote:
> Hello everyone,
> I'm trying to create custom Tkinter/Pmw widgets for my project.
> After testing my widgets under Unix (Solaris), I have tried them under
> Windows and I got a surprise.
> The widgets came out differently.
> The following simple code snippet demonstrates the difference:
> root = Tk()
> w = Canvas(root, width=12, height=12, bd=4, relief=RAISED,
> w.create_rectangle(5,5,16,16,fill='blue', outline='black')
> w2 = Canvas(root, width=12, height=12, bd=0, relief=RAISED,
> w2.create_oval(0,0,12+1,12+1,fill='blue', outline='')
> w3 = Canvas(root, width=32, height=32, bd=4, relief=RAISED,
> w3.create_oval(4+0,4+0,4+32+1,4+32+1,fill='blue', outline='')
> I noticed the difference because rectangle (or oval) object on the
> canvas covers the entire canvas such that small differences in size
> are very noticeable.
> As Tkinter is a thin wrapper layer for Tk, I'm suspecting the
> differences are rooted in Tk.
> I'm using TK8.5 under Unix while Python under Windows uses TK8.4.
> As I don't have any access to Python under Windows with TK8.5, I
> cannot verify if this problem is fixed under TK8.5 for Windows.
> So, here are my questions:
> (1) Can anybody who has access to Python under Windows with TK8.5 to
> verify if the problem is fixed.
> If the problem is fixed, rectangle and ovals are inscribed to the
> canvas boundary nicely.
> If not, you see the rectangle is off by one pixel and the radius is
> one pixel larger, I think. The boundary width is also not correct
> (right side is one pixel wider).
> (2) As the official distribution of Python under Windows uses TK8.4,
> what is the best approach to make my widgets to work correctly under
> both environment?
> - I could use sys.platform to code differently so that they look the
> - I'm afraid this creates a problem when TK8.5 is finally introduced
> to Python under Windows.
> Any suggestions?
I didn't really test your code, but I know there have been a few problems
with the Canvas relief and border for quite a while now. For example, the
Canvas border has a tendency to disappear when the Canvas is scrolled.
Don't know if it's fixed in the latest version.
The usual workaround is to create canvases with a flat relief and 0
border, and add the relief if you want one via a surrounding Frame. In
your example, for the first Canvas, that would be:
f = Frame(root, bd=4, relief=RAISED)
w = Canvas(f, width=12, height=12, bg='cyan')
w.create_rectangle(1, 1, 12, 12, fill='blue', outline='black')
This may solve your problem.
python -c "print ''.join([chr(154 - ord(c)) for c in
More information about the Python-list