You can make this work by changing your loop iterable to a tuple of these four entries:
entries = (self.entryplot_val1,
self.entryplot_val2,
self.entryplot_val3,
self.entryplot_val4)
for x in entries:
x.delete(0, tk.END)
Since you don't want to create this tuple every time, let's move it into object initialization:
def __init__(self):
# assuming you have a setup like the following
master = Tk()
self.entryplot_val1 = Entry(master)
self.entryplot_val2 = Entry(master)
self.entryplot_val3 = Entry(master)
self.entryplot_val4 = Entry(master)
# initialize your tuple to use in your for loop
self.entries = (self.entryplot_val1,
self.entryplot_val2,
self.entryplot_val3,
self.entryplot_val4)
# some further setup for entries
self.entryplot_val1.pack()
self.entryplot_val2.pack()
self.entryplot_val3.pack()
self.entryplot_val4.pack()
And then you can simplify this a bit further into:
def __init__(self):
# assuming you have a setup like the following
master = Tk()
self.entries = (Entry(master), Entry(master), Entry(master), Entry(master))
# some further setup for entries
for x in self.entries:
x.pack()
You can then use loops in the form of last example elsewhere in your class code.
Since you removed the previous identifiers for the entries, you would need to change your code to use the new tuple wherever they were used. That is, change references of self.entryplot_val1
to self.entries[0]
, self.entryplot_val2
to self.entries[1]
and so on.