How to get console info to display in win?

New to pprogramming

cannot find how to get console info which is correct to display in window

import tkinter as tk
import socket
from requests import get

root = tk.Tk(className=‘IP ADDRESS’)

def get_host_name_ip():
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
ext_ip = get(‘’).text

    print("IP : ", host_ip)
    print("Hostname :  ", host_name)
    print(f'My public IP address is: {ext_ip}')

    print("Unable to get Hostname and IP")

Driver code

get_host_name_ip() # Function call

T = tk.Text(root, height=10, width=50)

T.insert(tk.END, “IP address: \n”)
T.insert(tk.END, “host is: \n”)
T.insert(tk.END, “The external IP is: \n”)


What sort of console info are you trying to get? Can you show a really
simple example, a “Hello world” example that doesn’t require networking
or tkinter?

Also, while you are still writing your code, you should never, ever
write bare except clauses like this:

    # code here
    # Don't do this!
    print("Unable to get Hostname and IP")

Why can’t you get the hostname and IP address? How can I fix it? Who

Well, the computer did know, but then you, the programmer, came along
and threw away all the information that would let you debug the
problem, and replaced it with an error message that is almost as useless
as the cursed “An error occurred”. Great. What sort of error? How can I
fix it?

That sort of error message is not user-friendly, it is user-hostile.

And when you are debugging your own code, it is like trying to fix a
fault while wearing a blindfold.

As a programmer, a traceback showing which line of code failed, and why
it failed, is your best friend in the world. Bare except clauses are
almost always one of the worst things you can do in your code:

So help yourself: take out the try…except until you can see exactly
what sort of errors you get. Fix the ones which are bugs in your code.
(If any.) The ones which are temporary errors, like socket timeouts, you
might want to retry the operation. And then, only when you know what
precise unrecoverable errors can occur, should you catch them and then
decide whether to hide the information from your users:

“You want the truth? YOU CAN’T HANDLE THE TRUTH!!!”

or give them enough information to fix the problem themselves.