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
--
https://mail.python.org/mailman/listinfo/python-list