画布中心在tcl / tk

时间:2016-03-05 03:00:41

标签: tcl tk

如果我需要输入坐标,我怎样才能在画布的中心创建一个对象?

如果可能,我如何获得画布中心的坐标?

1 个答案:

答案 0 :(得分:1)

来自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"