Tkinter Canvas 将项目移动到顶层 [英] Tkinter Canvas move item to top level

查看:24
本文介绍了Tkinter Canvas 将项目移动到顶层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Tkinter Canvas 小部件(Python 2.7,而不是 3),在这个 Canvas 上我有不同的项目.如果我创建一个与旧项目重叠的新项目,它将在前面.我现在如何将旧项目移动到新创建的项目前面,甚至是画布上所有其他项目的前面?

I have a Tkinter Canvas widget (Python 2.7, not 3), and on this Canvas I have different items. If I create a new item that overlaps an old item, It will be in front. How can I now move the old item in front of the newly created one, or even in front of all other items on the Canvas?

到目前为止的示例代码:

Example code so far:

from Tkinter import *
root = Tk()
canvas = Canvas(root,width=200,height=200,bg="white")
canvas.grid()
firstRect = canvas.create_rectangle(0,0,10,10,fill="red")
secondRect = canvas.create_rectangle(5,5,15,15,fill="blue")

现在我希望 firstRect 位于 secondRect 的前面.

now I want firstRect to be in front of secondRect.

推荐答案

使用 tag_lower()tag_raise() 方法用于 Canvas> 对象:

Use the tag_lower() and tag_raise() methods for the Canvas object:

canvas.tag_raise(firstRect)

或者:

canvas.tag_lower(secondRect)

这篇关于Tkinter Canvas 将项目移动到顶层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆