I have a window with multiple labels. Instead of configuring each label individually, I want to use a for loop to configure them.
Basically, what I get from the below code is all labels are showing the text 'question #3', but I want each label label to show the right text accordingly - so label1 needs to have the text 'question #1', label2 needs to show 'question #2' and label3 needs to show 'question #3'. Can somebody please help.
from tkinter import *
root = Tk()
string = 'Question #'
nums = ['1', '2', '3']
#labels
label_1 = Label(root)
label_1.pack()
label_2 = Label(root)
label_2.pack()
label_3 = Label(root)
label_3.pack()
# end of labels
labels = [label_1, label_2, label_3]
for x in nums:
jk = string + x
for l in labels:
l.config(text=jk)
root.mainloop()
