我在Python中运行一些基本的GUI代码,使用TkInter:
# Making a blank canvas to "draw" on, it can easily be seen as it will be white
canvas = Canvas(root, width=500, height=500, background="white")
canvas.grid(row=6, column=5)
# Creating text to go within the boxes
officeText = canvas.create_text(125, 110, text="Office")
# Creating boxes within the canvas
officeGraphic = canvas.create_rectangle(100, 100, 150, 150, fill="orange")
然而,我遇到的问题是文本" office"出现在橙色框后面。如何将此文本带到前面?
答案 0 :(得分:2)
如果不能选择更改创作顺序,可以使用cavas' tag_raise
方法。
canvas.tag_raise(officeText)
答案 1 :(得分:1)
TK将按照他们创建的顺序绘制小部件,最后创建的小部件位于之前创建的小部件之上。使用该逻辑,您只需向下移动officeText
:
# Creating boxes within the canvas
officeGraphic = canvas.create_rectangle(100, 100, 150, 150, fill="orange")
# Creating text to go within the boxes
officeText = canvas.create_text(125, 110, text="Office")