Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter SpinBox getting the last value

Tags:

tkinter

I have a tkinter spinbox widget.

    val = IntVar()
    Spinbox(from_=1, to=10, textvariable=val, command=lambda:self.Fn(val.get()))

    def Fn(self, v):
        print v

When the spinbox is clicked, it prints value of new spin box value.

Instead I want the previous spinbox value - which could be one above or one below the current value.

Is there a way i can get the previous value ?

like image 363
bhaskarc Avatar asked Mar 05 '26 21:03

bhaskarc


1 Answers

You just need to store the value, and print it the next time the function is called:

def Fn(self, v):
    result = self._oldvalue
    self._oldvalue = v
    print(result)

Don't forget to initialize self._oldvalue with some default value.

like image 152
A. Rodas Avatar answered Mar 11 '26 10:03

A. Rodas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!