Thanks MRAB, for your advice. I will have close the connection before,
the code fixed are below.
def isInternet():
testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
testConn.settimeout(5)
output = testConn.connect_ex(('8.8.8.8', 80))
testConn.close() <-----------------------------------
if output == 0:
return True
else:
return False
El 19/03/19 a las 17:55, MRAB escribió:
On 2019-03-19 19:46, Informatico de Neurodesarrollo wrote:
Thanks for all yours recommendations, finally I was successfully
finished my first project about tkinter (and I hope, not the last).
Here is the finally code:
#!/usr/bin/env python
#
# DetectConn_2_0.py
#
#
from tkinter import *
import time, socket
def isInternet():
testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# Force a time limit to conect to the host (5 seg), may be more
or less
testConn.settimeout(5)
output = testConn.connect_ex(('10.44.0.1', 80))
The following lines will cause a return from the function, so the
testConn.close() line will never be reached.
Fortunately, the socket will be closed anyway, when the garbage
collection occurs.
if output == 0:
return True
else:
return False
testConn.close()
def colorupdate():
if isInternet():
root.config(background="#38EB5C")
else:
root.config(background="#F50743")
root.after(5000, colorupdate)
root = Tk()
root.title("Connection")
root.geometry("80x50")
root.resizable(width=False, height=False)
colorupdate()
root.mainloop()
Thanks again
--
Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.
--
Este mensaje le ha llegado mediante el servicio de correo electronico que
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema
Nacional de Salud. La persona que envia este correo asume el compromiso de usar
el servicio a tales fines y cumplir con las regulaciones establecidas
Infomed: http://www.sld.cu/
--
https://mail.python.org/mailman/listinfo/python-list