How to create multiple label using for loop
If You Want to create Multiple Label using for loop You can try this below code , Just Open your Code editor, copy and paste to this code.
from tkinter import *
my_window = Tk()
my_window.title("Multiple Label using for loop")
my_window.geometry("800x500+450+86")
my_window.config(bg="#B4EEB4")
string = 'Number * #'
nums = ['1', '2', '3']
#labels
label_1 = Label(my_window, font=("times", 20, "bold"), bg="#8A360F")
label_1.pack(pady=10)
label_2 = Label(my_window,font=("times", 20, "bold"), bg="#6495ED")
label_2.pack(pady=10)
label_3 = Label(my_window,font=("times", 20, "bold"), bg="#00EEEE")
label_3.pack(pady=10)
# end of labels
labels = [label_1, label_2, label_3]
for x, l in zip(nums,labels): #change your for loops to this
jk = string + x
l.config(text=jk)
my_window.mainloop()
Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.
Post a Comment