How can I make text appear in circle like in the picture?
Asked
Active
Viewed 945 times
1
-
2I'm not certain that it's even possible with just Tkinter. AFAIK, Tkinter's text-rendering capabilities don't provide any way to rotate text. – Kevin Mar 23 '20 at 14:04
-
Does this answer your question? [Is there a way to rotate text around (or inside) a circle?](https://stackoverflow.com/questions/56652414/is-there-a-way-to-rotate-text-around-or-inside-a-circle) – stovfl Mar 23 '20 at 14:27
-
@stovfl I've just quoted that question in my answer. – scotty3785 Mar 23 '20 at 14:30
-
@scotty3785 Yes, but this does not prevent me to vote as duplicate. – stovfl Mar 23 '20 at 14:34
1 Answers
0
This answer https://stackoverflow.com/a/56653517/2323393 suggests that you can use the angle
attribute of the text object to rotate it.
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()

scotty3785
- 6,763
- 1
- 25
- 35