Tkinter Unix and Windows incompatibility

akineko akineko at gmail.com
Wed Aug 27 06:50:30 CEST 2008


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,
bg='cyan')
    w.create_rectangle(5,5,16,16,fill='blue', outline='black')
    w.pack()

    w2 = Canvas(root, width=12, height=12, bd=0, relief=RAISED,
bg='purple')
    w2.create_oval(0,0,12+1,12+1,fill='blue', outline='')
    w2.pack()

    w3 = Canvas(root, width=32, height=32, bd=4, relief=RAISED,
bg='purple')
    w3.create_oval(4+0,4+0,4+32+1,4+32+1,fill='blue', outline='')
    w3.pack()

    root.mainloop()

//

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
same.
  - I'm afraid this creates a problem when TK8.5 is finally introduced
to Python under Windows.

Any suggestions?

Aki Niimura



More information about the Python-list mailing list