pythontkinterscaledefaultspinbox

How to make two Spin Boxes inTkinter to work independently


I am new to Tkinter and I' m developing an app that includes 2 Spinboxes. The code is the following:

from tkinter import *

   
vals1 = [1, 3, 5, 7]
vals2 = [2, 4, 6, 8, 10]

root = Tk()

SpB1Var = DoubleVar()
SpB2Var = DoubleVar()

FrInitial = Frame(root, width=800, height=400, bg="blue")
FrInitial.pack()

SpB1=Spinbox(FrInitial, values=vals1, textvariable=SpB1Var.get())
SpB1.place(x=281, y=130)

SpB2=Spinbox(FrInitial, values=vals2, textvariable=SpB2Var.get())
SpB2.place(x=581, y=130)

root.mainloop()

When I run it and I change the value of one Spinbox the other change value immediately.

How can I make them work independently? How can I set default value for the 1st Spinbox the value 5 instead of 1?

If I change the Spinboxes with Scales, it works fine. Why?

Thanks a lot


Solution

  • Do not use get() here. Just use the variable. Like this:

    SpB1 = Spinbox(FrInitial, values = vals1, textvariable=SpB1Var)