Tkinter无法在画布内提升项目

2024-09-29 01:29:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有4个项目在我的画布(画布12)。我试着把2个拖动按钮(frame1_drag/frame2_drag)放在窗口前面(frame2can/frame1can)。但我不能让tag嫒raise()或lift()做任何事情。现在拖动按钮卡在窗户后面。是的,必须是这样的,因为拖动按钮在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)

Tags: tag画布createsfwindow按钮raisedrag
1条回答
网友
1楼 · 发布于 2024-09-29 01:29:02

不能将绘制的项目放置在窗对象的顶部。在

根据官方的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; you must use the raise and lower Tk commands instead.

相关问题 更多 >