Can't change tkinter label text constantly in loop
<p>I'm trying to make simple Quiz program. I want labels to change their text for every question in range of 10 questions. So, when you are on 1st question, one label should show 'Question 1'. But it immediately shows 'Question 10', and I'm unable to play quiz.</p>

<p>In dictionary, there's only one question, but it should not be problem, it should repeat that question 10 times.</p>

<p>Here's piece of my code (It's in class):</p>

<pre><code>    self.label = tk.Label(self, text="This is page 1")
    self.label.pack(side="top", fill="x", pady=10)
    self.label1 = tk.Label(self, text='')
    self.label1.pack()
    self.label2 = tk.Label(self, text='')
    self.label2.pack()
    self.entry1 = tk.Entry(self)
    self.entry1.pack()
    self.label3 = tk.Label(self, text='')
    self.label3.pack()
    self.entry2 = tk.Entry(self)
    self.entry2.pack()

    my_dict = {
        "Base-2 number system": "binary",
    }

    score = 0

    for i in range(10):
        question = (random.choice(list(my_dict.keys())))
        answer = my_dict[question]
        self.label1.config(text=("Question " + str(i + 1)))
        self.label2.config(text=(question + "?"))

        guess = self.entry1.get()

        if guess.lower() == answer.lower():
                score += 1
        else:
                score += 0

    self.label3.config(text=("Your final score was " + str(score)))
</code></pre>

<p>You need to wait for the user to enter their answer into the Entry widget. The code you posted doesn't do that. You have to organize your logic a little differently in GUI programss  compared to command-line programs because you need to wait for events generated by user actions and then respond to them.</p>

<p>The code below doesn't do everything you want, but it does run. :) It displays a question, waits for the user to type their answer into the <code>self.entry1</code> widget, and when they hit the <code>Enter</code> key in that widget it calls the <code>.get_answer</code> method which processes their answer and then calls the <code>.ask</code> method to ask a new question. After 10 questions the program exits.</p>

<pre><code>import tkinter as tk
import random

class Quiz(tk.Frame):
    def __init__(self, root):
        super().__init__(root)
        self.root = root
        self.pack()

        self.label = tk.Label(self, text="This is page 1")
        self.label.pack(side="top", fill="x", pady=10)
        self.label1 = tk.Label(self, text='')
        self.label1.pack()
        self.label2 = tk.Label(self, text='')
        self.label2.pack()
        self.entry1 = tk.Entry(self)
        self.entry1.bind("&lt;Return&gt;", self.get_answer)
        self.entry1.pack()
        self.label3 = tk.Label(self, text='')
        self.label3.pack()
        self.entry2 = tk.Entry(self)
        self.entry2.pack()

        self.start_quiz()
        root.mainloop()

    def start_quiz(self):
        self.qdict = {
            "Base-2 number system": "binary",
            "Base-8 number system": "octal",
            "Base-16 number system": "hexadecimal",
        }
        self.qkeys = list(self.qdict.keys())
        self.score = 0
        self.count = 1
        self.ask()

    def ask(self):
        self.question = random.choice(self.qkeys)
        self.label1.config(text="Question {}".format(self.count))
        self.label2.config(text=self.question + "?")

    def get_answer(self, event):
        widget = event.widget
        guess = widget.get()
        answer = self.qdict[self.question]
        if guess.lower() == answer.lower():
            self.score += 1
        self.label3.config(text="Score: {}".format(self.score))

        self.count += 1
        if self.count &lt;= 10:
            self.ask()
        else:
            self.root.destroy()

Quiz(tk.Tk())
</code></pre>

python loops for-loop tkinter range