我正在尝试将输出值插入Tkinter标签。
这是我的代码:
def get_Host_name_IP():
try:
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
print("Hostname : ", host_name)
print("IP : ", host_ip)
outputtext = Text(host_ip)
except:
print("Unable to get Hostname and IP")
我希望将IP_adress显示在这样的标签中:
Label (window, text="IP adress", bg="black", fg="Black", font="none 11 bold") .grid(row=9, column=0, sticky=W)
感谢您的帮助!
答案 0 :(得分:0)
从类似于您的函数中返回host_ip
def get_IP():
try:
host_ip = socket.gethostbyname(host_name)
return host_ip
except:
print("Unable to get IP")
并在此使用:
Label (window, text=get_IP(), bg="black", fg="Black", font="none 11 bold") .grid(row=9, column=0, sticky=W)