0

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.')
martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    Does this answer your question? [Tkinter: AttributeError: NoneType object has no attribute ](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) – Thingamabobs May 02 '21 at 10:12
  • 1
    you need to call `self.IPdst.get()` – Thingamabobs May 02 '21 at 10:14
  • 1
    Hi Atlas435, it worked now =D, I realized I also did a real oopsie and confused the username variable with the IP variable in the entries... whoops. But definitely that helped me solve my previous problem. So thank you! – GreenManchego1984 May 02 '21 at 12:27

0 Answers0