title: Tkinter Spinbox range validation
body: <p>I'm trying to make use of this excellent answer by Bryan Oakley, but to no avail (<a href="https://stackoverflow.com/a/4140988/5060127">https://stackoverflow.com/a/4140988/5060127</a>)...</p>
  
  <p>I would like to use the same method to verify Spinbox values. I have defined from_ and to values for spinboxes, but user can still type most anything in them... it should be validated that only values within the from_-to range are possible to be inputted by the user, and only integers at that.</p>
  
  <p>Here's the code that shows how far I've got...</p>
  
  <pre><code>try:
      from Tkinter import *
  except ImportError:
      from tkinter import *
  
  class GUI:
      def __init__(self):
          # root window of the whole program
          self.root = Tk()
          self.root.title('ImageSound')
  
          # registering validation command
          vldt_ifnum_cmd = (self.root.register(self.ValidateIfNum),'%s', '%S')
  
          # creating a spinbox
          harm_count = Spinbox(self.root, from_=1, to=128, width=5, justify='right', validate='all', validatecommand=vldt_ifnum_cmd)
          harm_count.delete(0,'end')
          harm_count.insert(0,8)
          harm_count.pack(padx=10, pady=10)
  
      def ValidateIfNum(self, s, S):
          # disallow anything but numbers
          valid = S.isdigit()
          if not valid:
              self.root.bell()
          return valid
  
  if __name__ == '__main__':
      mainwindow = GUI()
      mainloop()
  </code></pre>