2
from tkinter import *
root=Tk()
root.title("")
#root.geometry("500x500")
global c
c=[]
def new():
    win=Toplevel()
    win.title("")
    for i in range(0,25):
        name=Label(win,text=str(c[i]),bg='#ADD8E6',fg='white',width=20)
        name.grid(column=1,row=i)
for i in range(1,26):
    name=Label(root,text='enter name of team'+str(i),bg='#ADD8E6',fg='white',width=20)
    name.grid(column=1,row=i)
    entry=Entry(root,bg='white',fg='black')
    entry.grid(column=2,row=i)
    c.append(entry.get())
submit=Button(root,text='Submit',bg='red',fg='white',command=new)    
submit.grid(column=1,row=26,columnspan=3)
root.mainloop()

after taking the input form different boxes in the first window , it does not put the same name in the 2nd window when required. It just sends a window whith the speciifed bgcolour

PLaese HElp

1 Answers1

0

The reason why you are not getting the right values is that when the program is run the Entry widgets are empty by default so the list is getting no values and when the button is pressed, it. displays labels text = "" on the second window.

To fix this, get the values of Entry widgets dynamically means get the values when the button is pressed. You can store each Entry widget into a list and later access them in the new function.

In your code, you just need to change two lines.

  1. Change c.append(entry.get()) with c.append(entry).
  2. In the new function change the argument value of "text" of label name from text=str(c[i]) to text=str(c[i].get()).
Saad
  • 3,340
  • 2
  • 10
  • 32
  • tnx a lot .. Worked like a charm – Practical Joker May 19 '20 at 04:53
  • it worked but still curious why didnt it work the other way around?? – Practical Joker May 30 '20 at 08:21
  • @PracticalJoker: I already explained it in my answer. Anyways, this is because you are getting the values of the `Entry` widget at the runtime when they're empty, this happens before the Tkinter window is visible. So stored the Entry widgets in the list which then can be accessed during the program. – Saad May 30 '20 at 08:32