I have a problem with the Entry
object of tkinter. basically, what I'm trying to do is receive an IP string from the user and first check if it null, then if is a valid ip address and then try to connect the client to the server socket. However...it seems as if the Entry
just doesn't know when the Entry
's empty or how to check if the ip address is valid.
Code:
self.IPdst = StringVar()
txt_IP = Entry(Login_frame, bd=5, textvariable = self.IPdst,
font = ('Arial', 14)).grid(row =1, column = 1, padx =20)
def is_ipv4(self):
try:
socket.inet_aton(self.IPdst)
return True
except socket.error:
return False
def TryToConnectIP(self):
if self.IPdst == '': #meaning empty
messagebox.showerror('Error', 'filling field is required.')
if self.is_ipv4() == True: #if ip address is valid computer will try to connect.
pass
else:
messagebox.showerror('Error', 'Invalid IP address, please try again.')