How to get the values of spinbox from and to in a function?
sbDays=tk.Spinbox(frame,from_=0,to=366)
sbDays.place(relx=initialX,rely=yDistance)
sbDays.configure(validate='all',validatecommand=(windows.register(validate),'%P'))
def validate(userInput):
if userInput=="":
return True
try:
val=int(float(userInput))
except ValueError:
return False
return val>=0 and val<=366
Instead of return val>=0 and val<=366. I need this:
minVal=spinbox 'from' value of '0'
maxVal=spinbox 'to' value of '366'
return val>=minVal and val<=maxVal
In C#, something like this:
minVal=this.From()
maxVal=this.To()
You can use the
cgetmethod to get attributes from a widget.In this case, you need
minVal = sbDays.cget("from")andmaxVal = sbDays.cget("to")Edit - For multiple spinboxes
To use this with multiple spinboxes, change the
validatecommandtovalidatecommand=(windows.register(validate),'%P', '%W')and change
validate(userInput)tovalidate(userInput, widget). Then replacesbDaysin my answer withwindows.nametowidget(widget)and it should work.The
%Win thevalidatecommandgives the name of the widget (from here), which is then used to get the widget withnametowidget(from here).