Why doesn't this work?

Chad Netzer cnetzer at mail.arc.nasa.gov
Mon Sep 30 18:17:43 EDT 2002


On Saturday 28 September 2002 23:29, Michael Bakkemo wrote:
> Why doesn't the rectangle start somewhere in the middle of the canvas
> (where one would expect (40,40) to be, instead of all the way over on
> the left?

Because of the way Tk works.  You are setting up a lot of things before 
entering the mainloop(), and not giving Tk a chance to execute and 
update it's internal state (not your fault, really).

But to fix things, add the line:

sc.update()

Just before:

rect = MovingRect(root, sc, 40,40, 10, 10)

(ie. right near the end of the program, but before the mainloop).  This 
let's the canvas get information from the window manager about how big 
the window that opened actually was, so it can position things like you 
expect it to.

-- 

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list