Reputation: 431
How can I create an object in the center of the canvas, given that I need to input coordinates?
If it's possible, how can I get the coordinates for the center of the canvas?
Upvotes: 0
Views: 190
Reputation: 658
From Bag of TK algorithms and also discussed in this google mailing list thread:
toplevel .child
set parent .
set child .child
# This should display $child centered in $parent
set w [winfo width $parent]
set h [winfo height $parent]
set x [winfo rootx $parent]
set y [winfo rooty $parent]
set xpos "+[ expr {$x+($w-[winfo width $child])/2}]"
set ypos "+[ expr {$y+($h-[winfo height $child])/2}]"
wm geometry $child "$xpos$ypos"
Upvotes: 1