Tkinter Unix and Windows incompatibility

Discussion in 'Python' started by akineko, Aug 27, 2008.

  1. akineko

    akineko Guest

    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
     
    akineko, Aug 27, 2008
    #1
    1. Advertising

  2. akineko

    Eric Brunel Guest

    On Wed, 27 Aug 2008 06:50:30 +0200, akineko <> 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,
    > 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?


    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)
    f.pack()
    w = Canvas(f, width=12, height=12, bg='cyan')
    w.create_rectangle(1, 1, 12, 12, fill='blue', outline='black')
    w.pack()

    This may solve your problem.

    HTH
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in
    'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
     
    Eric Brunel, Aug 27, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hannibal
    Replies:
    1
    Views:
    373
  2. Attys Erebos

    DTD and CSS incompatibility?

    Attys Erebos, Oct 31, 2005, in forum: HTML
    Replies:
    4
    Views:
    514
    Jim Higson
    Nov 1, 2005
  3. Alan Sung
    Replies:
    3
    Views:
    927
    visage
    Aug 6, 2003
  4. David Lees
    Replies:
    1
    Views:
    297
    David Lees
    Mar 7, 2004
  5. KMyers1
    Replies:
    2
    Views:
    418
    KMyers1
    Jul 20, 2007
Loading...

Share This Page