import tkinter as tk
my_w = tk.Tk()
my_w.geometry("400x250") # Size of the window
my_w.title("www.plus2net.com") # title
my_w.mainloop() # Keep the window open
Number of inputs required can change, here we are keeping one variable and value of this can be changed to dynamically create and manage the Entry widgets along with the Label. Note that this requirement ( value ) can come from different sources.
number_of_inputs=5 # Number of entries required
To store the references of the Entry widgets we will create one blank list. To this list we will add reference of our Entry widgets by using list append method.
ref=[] # to store the references
for j in range(number_of_inputs):
l=tk.Label(my_w,text='Entry: '+str(j+1),font=20,fg='blue')
l.grid(row=j,column=0,padx=3)
e = tk.Entry(my_w, font=20,bg='lightyellow')
e.grid(row=j, column=1,padx=10,pady=3)
ref.append(e) # store references
b1=tk.Button(my_w,text='Submit',
bg='lightgreen',command=lambda: my_check(),font=18)
b1.grid(row=j+1,column=0,padx=3,pady=5)
l1=tk.Label(my_w,text='Output here',font=20) # display message
l1.grid(row=j+1,column=1)
On click of the Submit button the function my_check() is executed and first we set a flag my_flag=True
. Based on the final value of this flag we will show the matching message using the label l1. def my_check():
my_flag=False
for w in ref:
if(len(w.get())<3):
#print(w.get())
my_flag=True
if(my_flag==False):
l1.config(text="Form can be submitted",fg='green')
else:
l1.config(text="Fill all the entries",fg='red' )
l1.after(3000, lambda: l1.config(text=''))
Full code is here
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("400x250") # Size of the window
my_w.title("www.plus2net.com") # title
number_of_inputs=2 # Number of entries required
ref=[] # to store the references
for j in range(number_of_inputs):
l=tk.Label(my_w,text='Entry: '+str(j+1),font=20,fg='blue')
l.grid(row=j,column=0,padx=3)
e = tk.Entry(my_w, font=20,bg='lightyellow')
e.grid(row=j, column=1,padx=10,pady=3)
ref.append(e) # store references
def my_check():
my_flag=False
for w in ref:
if(len(w.get())<3):
#print(w.get())
my_flag=True
if(my_flag==False):
l1.config(text="Form can be submitted",fg='green')
else:
l1.config(text="Fill all the entries",fg='red' )
l1.after(3000, lambda: l1.config(text=''))
b1=tk.Button(my_w,text='Submit',
bg='lightgreen',command=lambda: my_check(),font=18)
b1.grid(row=j+1,column=0,padx=3,pady=5)
l1=tk.Label(my_w,text='Output here',font=20) # display message
l1.grid(row=j+1,column=1)
my_w.mainloop() # Keep the window open
Entry Dynamic Buttons
Dynamic Label
Dynamically managing Spinboxes Label
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.