i'm beginner and I would to like to know if there is some way to make a function that repeats itself changing valor the valor of some variables...
For example:
def example():
box1.delete(0,END) #Here I would like to change the variable "box1" to "box2" and "box3"
get1=box1.get() #Here I would like to change the variable "box1" to "box2" and "box3"
Well, I think that is all. I hope you can help me. Thank you!
Usually, you would make box
an argument to the function and call it repeatedly with all the boxes you want to operate on:
def example(box):
box.delete(0, END)
get = box.get()
...
for box in box1, box2, box3, box4:
example(box)
if example
actually returns something (e.g. the data that box.get
returned), you can use a list comprehension.
boxes = (box1, box2, box3, box4)
data = [example(box) for box in boxes]
Now data
is a list with one element from each element in boxes
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments