[SOLVED] Show ip address in Entry Python

Issue

What problem i want show ip address local system in root

from tkinter import *
import socket

root = Tk()
root.geometry("640x480")
root.title("IT")

def ipadds():
    hostname = socket.gethostname()
    local_ip = socket.gethostbyname(hostname)

L1 = Label(root,text="Your IP is :", font=('Arial',10)).place(x=30,y=50)
E1 = Entry(root,width = 20,command=ipadds).place(x=95,y=50)
root.mainloop()

Is correct use command in Entry?

Solution

There is no command option in Entry. Also need to adjust root.geometry. Your Entry code returns None so need to pack before place. To get an entry showing need to use insert.

from tkinter import *
import socket
root = Tk()
root.geometry("640x480+80+80")
root.title("IT")

def ipadds():
    hostname = socket.gethostname()
    local_ip = socket.gethostbyname(hostname)
    return local_ip

L1 = Label(root,text="Your IP is :", font=('Arial',10)).place(x=30,y=50)
E1 = Entry(root,width = 20)
E1.pack()
E1.place(x=95,y=50)
ip = ipadds()
E1.insert('0',ip)
root.mainloop()

Answered By – InhirCode

Answer Checked By – Marie Seifert (BugsFixing Admin)

Leave a Reply

Your email address will not be published.