I want that you can only enter numbers in the spinbox
as in this question they do it in html
and js
, what I have done is the following code
self.infectedDefauld = tk.StringVar(self)
self.infectedDefauld.set("1")
self.populationSpin = tk.Spinbox(self.leftFrame, from_=1, to=100, width=5, bg=colorFive, fg=colorFour, textvariable=self.totalDefauld, bd=10, relief="flat")
self.populationSpin.pack(side="top", pady=5)
self.totalDefauld.trace(mode="w", callback=self.onValidationPopulation)
def onValidationPopulation (self, varname, elementname, mode):
m = re.search(r'\d+', self.populationSpin.get())
if m:
self.totalDefauld.set(m.group(0))
else:
self.totalDefauld.set(0)
the problem is that when I write for example 2 it changes to 20