[英]How can I make text appear in circle
This answer https://stackoverflow.com/a/56653517/2323393 suggests that you can use the angle
attribute of the text object to rotate it.这个答案https://stackoverflow.com/a/56653517/2323393建议您可以使用文本对象的
angle
属性来旋转它。
For example例如
txt = canvas.create_text(250, 250, text='Hi')
canvas.itemconfig(txt, angle=90)
Or a more complete solution或者更完整的解决方案
import math
import tkinter as tk
def draw(angle, text):
x = math.cos(math.radians(angle)) * 50 + 250
y = math.sin(math.radians(angle)) * 50 + 250
obj = canvas.create_text(250, 250, text=text, fill="green")
canvas.itemconfig(obj, angle=-angle)
canvas.coords(obj, x, y)
return obj
root = tk.Tk()
canvas = tk.Canvas(root, width=500, height=500)
for i in range(0,360,60):
draw(i,"Hi")
canvas.pack()
root.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.