簡體   English   中英

如何使文本顯示在框的前面?

[英]How can I make text appear in front of a box?

我正在使用TkInter在Python中運行一些基本的GUI代碼:

# 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")

但是,我遇到的問題是在橙色框后面出現了“辦公室”字樣。 我怎樣才能把這段文字放在最前面?

如果不能更改創建順序,則可以使用cavas的tag_raise方法。

canvas.tag_raise(officeText)

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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM