I have the following code which works and gives me each value. I can’t seem to create a list of all the values once they are collected. I’m currently getting one value at a time..! I’ve tried the two following ways:
def numberwritten(self, event, key, index):
self.values = []
if not self.left[index]:
self.box[key].config(fg='black')
self.left[index] = True
self.values.append(self.box[key].get())
print self.values
This works with just one value being printed each time but I would like a list I can assign ‘n’ variables to (the number of values obtained changes at random each time).
I would like to do for example ‘Value %s” % i = value obtained.
self.values = []is clearing the list each time you callnumberwritten()so that is why you are printing just one value. Declareself.valuesglobally or in the__init__()function in your class.In terms of formatting for printing one value during each loop iteration, try something like this:
Edit: I borrowed the following from this answer if you actually want to print your entire list each loop iteration: