简体   繁体   English

Tkinter无法在画布中提起物品

[英]Tkinter can't lift item within canvas

I have 4 items in my canvas (canvas12). 我的画布(canvas12)中有4个项目。 I'm trying to place the 2 drag buttons (frame1_drag/frame2_drag) in front of the windows (frame2can/frame1can). 我正在尝试将2个拖动按钮(frame1_drag / frame2_drag)放在窗口前面(frame2can / frame1can)。 But I can't get tag_raise() or lift() to do anything. 但是我无法让tag_raise()或lift()做任何事情。 Right now the drag buttons are stuck behind the windows. 现在,拖动按钮卡在了窗口的后面。 And yes, it has to be this way because the drag buttons animate their respective framexcan window within canvas12. 是的,必须这样,因为拖动按钮在canvas12中为其各自的framexcan窗口设置动画。

frame2can = canvas12.create_window(0, 0, anchor='nw', width=sf(768), height=sf(fr1h),window=frame2)
frame1can = canvas12.create_window(0, sf(fr1h), anchor='nw', width=sf(768), height=sf(fr1h),window=frame1)

# Drag Buttons
frame1_drag = canvas12.create_rectangle(0, 0, sf(fr0h), sf(fr0h), outline="blue", fill="green", tags="token")
frame2_drag = canvas12.create_rectangle(0, sf(fr1h), sf(fr0h), sf(fr0h+fr1h), outline="blue", fill="green", tags="token")

canvas12.tag_raise(frame1_drag)
canvas12.tag_raise(frame2_drag)

You cannot place drawn items on top of window objects. 您不能将绘制的项目放在窗口对象的顶部。

From the official tk documentation: 从官方的tk文档中:

The items in a canvas are ordered for purposes of display, with the first item in the display list being displayed first, followed by the next item in the list, and so on. 为了显示的目的,对画布中的项目进行了排序,显示列表中的第一个项目被首先显示,随后是列表中的下一个项目,依此类推。 Items later in the display list obscure those that are earlier in the display list and are sometimes referred to as being “on top” of earlier items. 显示列表中较晚的项目会使显示列表中较早的项目模糊不清,有时被称为在较早项目的“顶部”。 When a new item is created it is placed at the end of the display list, on top of everything else. 创建新项目时,它将放置在显示列表的末尾,在所有其他项目的顶部。 Widget commands may be used to re-arrange the order of the display list. 窗口小部件命令可用于重新排列显示列表的顺序。

Window items are an exception to the above rules. 窗口项是上述规则的例外。 The underlying window systems require them always to be drawn on top of other items. 底层窗口系统要求始终将它们绘制在其他项目之上。 In addition, the stacking order of window items is not affected by any of the canvas widget commands; 另外,窗口项目的堆叠顺序不受任何canvas小部件命令的影响; you must use the raise and lower Tk commands instead. 您必须改用提高和降低Tk命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM