I'm a beginner in Python. How do I change the value of a label dynamically?
To be more specific, I have the following code:
#!/usr/bin/env python
from Tkinter import *
import socket, webbrowser
root = Tk()
root.title("Test - waghcwb")
def window(w=300, h=200):
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
window(270, 100)
def Open():
text_contents = text.get()
url = str(socket.gethostbyname( text.get() ))
if url != '0.0.0.0':
webbrowser.open("http://%s" %url)
else:
#Erro para a label aqui
print("Erro")
info = Label(root, text="Testando", pady=20).pack()
text = Entry(root, width=40).pack()
button = Button(root, text="Enviar", command=Open, width=40).pack()
error = Label(root, text="", pady=5)
root.mainloop()
Note the else:
there, that's where I'd like to insert my error message.
My idea was to leave an empty label there and only enter data when there is an error, but as I said I'm a good beginner and I do not know any way to do that.