Multiple outputs printed slowly at the same time
<p>As it's stated in the title, I have N strings (let's say 3) and they go one after the other like:</p>

<pre><code>"string1"
"string2"
"string3"
</code></pre>

<p>With the help of 'sleep' we can make the string get printed out slowly, symbol by symbol, BUT I want to have each of them printed slowly AT THE SAME TIME. Is it possible to do such a thing?  </p>

<p>Problem - lvl.'Advanced': Can I make 3 tkinter buttons with text in them printed like that? Or maybe it'd be better to create labels with such text-effect (if possible) and instantly replace them with 3 buttons with the same words?</p>

<p>If I understand you correctly, you want to create a label that slowly reveals one character at a time (ie: first you see "s", then "st", then "str", etc).</p>

<p>That can be cone by creating a custom label class, and using <code>after</code> to slowly reveal the text. Each time the function <code>reveal_text</code> is called, it pops one character off of the list of remaining characters, appends it to the characters already displayed, and then arranges for itself to be called again in half a second.</p>

<p>For example:</p>

<pre><code>class SlowLabel(tk.Label):
    def __init__(self, *args, **kwargs):
        tk.Label.__init__(self, *args, **kwargs)

        self.text = self.cget("text")
        self.configure(text="")

        self.reveal_text()

    def reveal_text(self):
        if len(self.text) &gt; 0:
            text = self.cget("text") + self.text[0]
            self.configure(text=text)
            self.text = self.text[1:]
            self.after(500, self.reveal_text)
</code></pre>

<p>You can use this class exactly like you would use a normal label:</p>

<pre><code>import tkinter as tk
root = tk.Tk()
for text in ("string1", "string2", "string3"):
    label = SlowLabel(root, text=text, width=20, anchor="w")
    label.pack(side="top", fill="x")
</code></pre>

<p>If you prefer buttons rather than labels, just inherit from <code>tk.Button</code> rather than <code>tk.Label</code>.</p>

python python-3.x tkinter