title: Tkinter Entry validation for IP Address
body: <p>I am taking IPv4 address as an input from the user, using Tkinter Entry and I would prefer using the validatecommand attribute of the widget which will only allow entries with the format XXX.XXX.XXX.XXX, being X digits.</p>
  
  <p>The problem can be solved with re module matching the entry with the expression ^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$ but I would like to do it beforehand.</p>
  
  <p>I have tried using the ipaddress module as follows:</p>
  
  <pre><code>import tkinter as tk
  import ipaddress as ip
  import re
  
  def validate(value):
      if ip.ip_address(value):
          return True
      return False
  
  window = tk.Tk()
  
  tk.Label(window, text = "IP", font = 'Arial 10 bold').grid(row = 0, column = 0, padx = 5, pady = 5, sticky = 'ew')
  varip = tk.StringVar()
  vcmd = window.register(validate)
  ipadd = tk.Entry(window, textvariable = varip, width = 23, validate = 'key', validatecommand = (vcmd, '%P'))
  ipadd.grid(row = 0, column = 1, padx = 5, pady = 5)
  window.mainloop()
  </code></pre>
  
  <p>The thing is that only the first character introduced is checked to be an IPv4 address and all characters are permitted, not only digits and dots.</p>
  
  <p>How could it be done?</p>