Making text shrink and expand enlessly in tkinter canvas
<p>Basically, I wanted to make a program that would create a text in the cavas with the size 1, rotate it by 180 degrees (continuosly) and while that expand it to its full size (let's say 50) than keep rotating it and by the time it has made a full it spin it would have shrunk down to 1 again and then repeat the process.</p>

<p>This is the only think I've come up with and keep in mind I've been only messing around with Python for a week or two so the code will probably need to be completly changed.</p>

<pre><code>from tkinter import *
import time
import random

size=1
angl=0
i=0

canvas=Canvas(width=600, height=600)
canvas.pack()

while i&lt;180:
    canvas.delete("all")
    canvas.create_text(150,150, text="kappa123",angle=angl,font=("helvetica",size))
    angl+=1
    size+=1
    i+=1
    canvas.update()
    time.sleep(1/360)

while i&gt;=180:
    canvas.delete("all")
    canvas.create_text(150,150, text="kappa123",angle=angl,font=("helvetica",size))
    angl+=1
    size-=1
    i+=1
    canvas.update()
    time.sleep(1/360)
</code></pre>

<p>As you can see, it only works once adn then expands forever.</p>

<p>I believe it is because you aren't leaving the second loop. your i variable moves on into infinity. To see an example run this and look at the output:</p>

<pre><code>from tkinter import *
import time
j = 0   # Time spent in the first while loop
k = 0   # Time spent in the second while loop
size = 1
angl = 0
i = 0

canvas = Canvas(width=600, height=600)
canvas.pack()

while i &lt; 180:
    canvas.delete("all")
    canvas.create_text(150, 150, text="kappa123", angle=angl, font=("helvetica", size))
    angl += 1
    size += 1
    i += 1
    j += 1
    print('First loop', j)
    canvas.update()
    time.sleep(1 / 360)

while i &gt;= 180:
    canvas.delete("all")
    canvas.create_text(150, 150, text="kappa123", angle=angl, font=("helvetica", size))
    angl += 1
    size -= 1
    i += 1

    k += 1
    print('Second loop', k)
    canvas.update()
    time.sleep(1 / 360)
</code></pre>

<p>A good solution to your problem, depending on your skill and comfort level, would be to create two functions, one to grow and one to shrink. Use the grow function to go from 1 to 180, then call the shrink function when you have iterated through and shrink from 180 to 1.</p>

<p><strong>Edit</strong></p>

<pre><code>class Spinner(Canvas):
    def __init__(self, parent):
        self.size = 1
        # Other data
        self.pack()

    def expand(self):
        for i in range(0, 181):
            self.angl += 1
            # increment size, update, sleep
        self.shrink()

    def shrink(self):
        for i in range(0, 181):
            # increment angle, decrease size, update, sleep
        self.expand()

root = Tk()
canvas = Spinner(root)
root.mainloop()
</code></pre>

python canvas tkinter tkinter-canvas