Guest User

Login

a guest
Apr 2nd, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. #import the 'tkinter' module
  2. import tkinter
  3. #sets variable secs to be used in countdown
  4. sec=5
  5. import urllib.request
  6. import base64
  7. URL = "https://lh3.googleusercontent.com/5oh994t2XLUThXYZQgeH3lv7Zv0cAHh8qJPuK82tqES6oFDASv4j43D0Hsps84_IhjM=w300"
  8. u = urllib.request.urlopen(URL)
  9. raw_data = u.read()
  10. u.close()
  11. b64_data = base64.encodestring(raw_data)
  12. #definding func that checks pass and username and if correct opens window
  13. def newWin():
  14. #getting pass and username
  15. password=entPassword.get()
  16. username=entUsername.get()
  17. if username=='user' and password=='pass': #if username and password is correct run this
  18. #creats a new window with black background
  19. win=tkinter.Tk()
  20. win.configure(background='black')
  21. #creates a label
  22. lbl=tkinter.Label(win,text="Hello",fg='red',bg='black',font=("symbol", 32))
  23. lbl.pack()
  24. win.after(5000,win.destroy) #close window after 5 seconds, 5000 miliseconds=5 seconds
  25. else: #if username or password is wrong run this
  26. root = tkinter.Tk() #opens up new window with message
  27. lbl=tkinter.Label(root,text='This program will shut down in...', fg='red',bg='black', font=('Helvetica',32))
  28. lbl.pack()
  29. root.configure(bg='black')
  30. #sets a label with no text
  31. time = tkinter.Label(root, fg='red',bg='black',font=('Helvetica',32))
  32. time.pack()
  33. #adds text to the lable
  34. #this is a countdown timer
  35. def tick():
  36. #calls on the variable sec
  37. global sec
  38. #sets sec as the text for the empty label
  39. time['text']=sec
  40. sec-=1
  41. #if sec is larger than negative one run this function again (removes 1 from sec and sets as new text value)
  42. if sec>-1:
  43. #only runs even 1000 milliseconds (1 second)
  44. time.after(1000,tick)
  45. else: #once sec has passed 0 run this
  46. #closes countdown window
  47. root.destroy()
  48. #closes main window
  49. window.destroy()
  50. #starts the countdown
  51. tick()
  52. root.mainloop()
  53. #create a new window
  54. window = tkinter.Tk()
  55. #set the window background to hex code '#a1dbcd'
  56. window.configure(background="#a1dbcd")
  57. #set the window title
  58. window.title("Welcome")
  59.  
  60. photo = tkinter.PhotoImage(data=b64_data)
  61. w = tkinter.Label(window, image=photo)
  62. w.pack()
  63.  
  64. #create a label for the instructions
  65. lblInst = tkinter.Label(window, text="Please login to continue:", fg="#383a39", bg="#a1dbcd", font=("Helvetica", 16))
  66. #and pack it into the window
  67. lblInst.pack()
  68.  
  69. #create the widgets for entering a username
  70. lblUsername = tkinter.Label(window, text="Username:", fg="#383a39", bg="#a1dbcd")
  71. entUsername = tkinter.Entry(window)
  72. #and pack them into the window
  73. lblUsername.pack()
  74. entUsername.pack()
  75.  
  76. #create the widgets for entering a username
  77. lblPassword = tkinter.Label(window, text="Password:", fg="#383a39", bg="#a1dbcd")
  78. entPassword = tkinter.Entry(window)
  79. #and pack them into to the window
  80. lblPassword.pack()
  81. entPassword.pack()
  82.  
  83. #create a button widget called btn
  84. btn = tkinter.Button(window, text="Login", fg="#a1dbcd", bg="#383a39",command=newWin)
  85. #pack the widget into the window
  86. btn.pack()
  87.  
  88. #draw the window, and start the 'application'
  89. window.mainloop()
Add Comment
Please, Sign In to add comment