I have a tkinter spinbox:
sb = Spinbox(frame, from_=1, to=12)
I would like to set the default value of spinbox to 4. How do i do this ?
i have read this thread where Bryan suggests setting
Tkinter.Spinbox(values=(1,2,3,4))
sb.delete(0,"end")
sb.insert(0,2)
But i did not get the logic behind it.
What has delete and insert to do with setting default values ?
Any further insight would be appreciated.
thanks
sb.delete(0,"end")
is used to remove all the text from the Spinbox, and with sb.insert(0,2)
you insert the number 2 as the new value.
You can also set a default value with the textvariable
option:
var = StringVar(root)
var.set("4")
sb = Spinbox(root, from_=1, to=12, textvariable=var)
As shortcut you could use:
var = tk.DoubleVar(value=2) # initial value
spinbox = tk.Spinbox(root, from_=1, to=12, textvariable=var)
Optional you may make the value readonly:
spinbox = tk.Spinbox(root, from_=1, to=12, textvariable=var, state='readonly')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With