2014-10-30 163 views
0

我想在计时器上显示鼠标位置。我用winfo_pointerxy(),这里是从my_func,并将部分代码():在画布上绘图// python tkinter

curr_x, curr_y = mouseFrame.winfo_pointerxy() 
curr_x = mouseFrame.canvasx(curr_x) 
curr_y = mouseFrame.canvasy(curr_y) 
mouseFrame.create_oval(curr_x, curr_y, curr_x + 5, curr_y + 5, fill='green') 
start_btn.after(time_interval, my_func) 

好像我用canvasx()错误的原因仍然返回从屏幕的左上方的位置计算。

回答

1

根据该tkinter reference(我不断用)

由于帆布可以比窗口变大,并配备 滚动在窗口中移动的整体画布,有 两个坐标

The window coordinates of a point are relative to the top left 
corner of the area on the display where the canvas appears. 

The canvas coordinates of a point are relative to the top left 
corner of the total canvas. 

如果你的画布是针对窗口(显示器)的左上角,你有没有滚动画布,在T:每个帆布系统我的坐标套应该是是一样的。