0

My problem at the moment is that I have entries which will be filled out by the user but I am trying to store them in a list so that it makes it easier to do maths using things like list[0] * list[1].I would also like to know how to store the entries in a save file sort of thing so I save it and it can be re-launched with their previous data that they have entered. any links will be appreciated too.

def save_entries():
    #entry recieve point 
    entry0.get(entry_values.append(int(juveniles_entry)))
    entry1.get(entry_values.append(int(adults_entry)))
    entry2.get(entry_values.append(int(seniles_entry)))

    entry3.get(entry_values.append(int(survival_rate_juveniles_entry)))
    entry4.get(entry_values.append(int(survival_rate_adults_entry)))
    entry5.get(entry_values.append(int(survival_rate_seniles_entry)))
    entry6.get(entry_values.append(int(birth_rate_entry)))
    entry7.get(entry_values.append(int(disease_trigger_point_entry)))

that is my current code which I am fairly certain is wrong for storing it in a list.

albert
  • 8,027
  • 10
  • 48
  • 84
2C00L4U
  • 9
  • 1
  • 7
  • Do you want to have the entry widget stored in a list or just the values of them? Could you please provide a minimum working example in order to have a basis to help you out. As an idea: You can bind a so-called `textvariable` to each entry widget to get and set its value. Those textvariables could be stored in e.g. a list or a dict. You can then pickle that list to your disk in order to save and restore the input-values next time opening your GUI. – albert Jul 25 '16 at 09:11

1 Answers1

2

Store the widget references in a list:

import Tkinter as tk
...
entries = []
for i in range(10):
    entry = tk.Entry(...)
    entries.append(entry)

later, when you need the values you can iterate over the list:

values = [int(entry.get()) for entry in entries]
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • However I try typing the code if i put it under def save_entries or else where it doesn't seem to work coming up with problems like class Tk has no attribute 'entry' (Tk is spelt correctly because i'm in python 2.7.11) – 2C00L4U Aug 03 '16 at 07:05