Guest User

Untitled

a guest
Feb 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import urllib
  2. import urllib.request as url
  3. from tkinter import *
  4.  
  5. master = Tk()
  6. master.geometry("280x36")
  7. master.resizable(False, False)
  8. master.config(bg="#4b4b4b")
  9. master.overrideredirect(True)
  10.  
  11. master.wm_geometry("-0-40")
  12. master.wm_attributes("-topmost", 1)
  13.  
  14. connectStatus = Label(bg="#e67e22", fg="#fff", width=29, height=1, text="Pending", font="Bahnscrift 10")
  15. connectStatus.place(x=10,y=8)
  16.  
  17. closeButton = Button(width=2, bg="#706f6f", fg="#fff", borderwidth=0, text="x", command=master.destroy)
  18. closeButton.place(x=253, y=8)
  19.  
  20. def displayCheck():
  21. colorFlash = "#38f789" if callbackAttempt == 1 else "#ff6656"
  22. connectStatus.config(bg=colorFlash)
  23. master.after(10, runRefresh)
  24.  
  25. def runRefresh():
  26. attemptConnect()
  27. master.after(2000, displayCheck)
  28.  
  29. def attemptConnect():
  30. global callbackAttempt
  31.  
  32. try:
  33. callbackAttempt = 1
  34. callback = url.urlopen("https://stackoverflow.com", timeout=1)
  35. connectStatus.config(text="Connection Established", font="Bahnscrift 10", bg="#2ecc71")
  36. callback.close()
  37.  
  38. except urllib.error.URLError:
  39. connectStatus.config(text="No Connection", bg="#e74c3c", font="Bahnscrift 10")
  40. callbackAttempt = 0
  41.  
  42. master.after(5, runRefresh)
  43. master.mainloop()
Add Comment
Please, Sign In to add comment