Sander Huisman Sander Huisman - 7 months ago 12
Python Question

make a loop with a button

I have a problem with the python script i'm working with. The problem is, when i press a (plus)button it need to multiply the display number. For example, you pressed the button ones it displays 0.05mm, when the button is pressed again it need to say 0.1mm etc. This is with steps of 0.05mm per press. I have looked for some examples but i can't compare it with my problem.

What i already have is this:

sum = 0
i = 0
while i<10:
sum = sum + i - sum
print (sum)
i = i + 0.05


It has no pauze or something like that, When 10 is passed it stops.

Have someone any solution of my problem?

Answer

From my understanding of the question, you only want to increment the sum by 0.05 each time you press the button (If I misunderstood, all you have to change is the operation inside the function). Just make the button call the function

value = 0

def increment():
    global value
    value += 0.05
    print value
Comments