Remi.b
Remi.b

Reputation: 18239

Python/Tkinter. A button that stores all Entry's in a list

I'd like to create a function (I called it super_function below) that closes the window, records all the information written in the different Entry and store it in a list.

Here is my current code:

from Tkinter import *

def super_function():
    # super_function that should store Entry info
    # in a list and close the window

fen1 = Tk()
entr = []
for i in range(10):
    entr.append(Entry(fen1))
    entr[i].grid(row=i+1)

Button(fen1, text = 'store everything in a list', command = fen1.quit).grid()

fen1.mainloop()

Thank you!

Upvotes: 1

Views: 871

Answers (1)

user2555451
user2555451

Reputation:

This should do it:

from Tkinter import *

def super_function():
    out = map(Entry.get, entr)
    fen1.destroy()
    print out

fen1 = Tk()
entr = []
for i in xrange(10):
    entr.append(Entry(fen1))
    entr[i].grid(row=i+1)

Button(fen1, text = 'store everything in a list', command = super_function).grid()

fen1.mainloop()

When you press the button, everything that is in the Entries is gathered into a list which is then printed in the terminal. Then the window closes.

Upvotes: 1

Related Questions