【发布时间】:2016-03-05 03:00:40
【问题描述】:
如果我需要输入坐标,如何在画布中心创建一个对象?
如果可能的话,如何获取画布中心的坐标?
【问题讨论】:
如果我需要输入坐标,如何在画布中心创建一个对象?
如果可能的话,如何获取画布中心的坐标?
【问题讨论】:
来自Bag of TK algorithms 并在此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"
【讨论】: