如何在python-tkinter的画布文本上放置轮廓? [英] How to put an outline on a canvas text on python -- tkinter?
本文介绍了如何在python-tkinter的画布文本上放置轮廓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在画布中央创建了一个白色文本,但我的背景非常丰富多彩,其中一部分颜色非常浅,所以我的句子的某些角落没有出现.我找不到任何设置边框或轮廓的选项.我能做什么?
I've created a white text in the center of my canvas, but my background is very colorful and one part of it is a very light color, so some corners of my sentence doesn't appear. I can't find any options to set borders or an outline. what could I do?
推荐答案
创建一个文本项,获取该项的边界框,使用该数据创建一个矩形,然后将文本提升到矩形上方.
Create a text item, get the bounding box of that item, use that data to create a rectangle, and raise the text above the rectangle.
import Tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, background="white")
canvas.pack(fill="both", expand=True)
text_item = canvas.create_text(20, 20, anchor="w", text="Hello world!", fill="white")
bbox = canvas.bbox(text_item)
rect_item = canvas.create_rectangle(bbox, outline="red", fill="black")
canvas.tag_raise(text_item,rect_item)
root.mainloop()
这篇关于如何在python-tkinter的画布文本上放置轮廓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文