Consider this simple code:
from tkinter import *
root = Tk()
def update_label():
my_label.config(text = my_var.get())
my_label = Label(root, text = "?")
my_label.pack()
my_var = IntVar()
Spinbox(root, from_ = 1, to = 10, textvariable = my_var, command = update_label).pack()
root.mainloop()
The documentation at New Mexico Tech states that:
The user can also enter values directly, treating the widget as if it were an Entry.
However if I enter a value directly in the SpinBox from the above code, it does not trigger the command callback.
Further, I can enter any value in the SpinBox widget despite the fact that I have restricted its -from
and _to
values between 1 and 10.
My questions:
Can I do something so that a direct entry in spinbox triggers the command callback ?
Can I restrict the value that can be entered directly within 1 and 10 ?