Advertisement
Guest User

Untitled

a guest
Jan 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. from tkinter import *
  2. import os
  3.  
  4. creds = 'tempfile.temp' # This just sets the variable creds to 'tempfile.temp'
  5.  
  6. def Signup(): # This is the signup definition,
  7. global pwordE # These globals just make the variables global to the entire script, meaning any definition can use them
  8. global nameE
  9. global roots
  10.  
  11. roots = Tk() # This creates the window, just a blank one.
  12. roots.title('Signup') # This renames the title of said window to 'signup'
  13. intruction = Label(roots, text='Please Enter new Credidentials\n') # This puts a label, so just a piece of text saying 'please enter blah'
  14. intruction.grid(row=0, column=0, sticky=E) # This just puts it in the window, on row 0, col 0. If you want to learn more look up a tkinter tutorial :)
  15.  
  16. nameL = Label(roots, text='New Username: ') # This just does the same as above, instead with the text new username.
  17. pwordL = Label(roots, text='New Password: ') # ^^
  18. nameL.grid(row=1, column=0, sticky=W) # Same thing as the instruction var just on different rows. :) Tkinter is like that.
  19. pwordL.grid(row=2, column=0, sticky=W) # ^^
  20.  
  21. nameE = Entry(roots) # This now puts a text box waiting for input.
  22. pwordE = Entry(roots, show='*') # Same as above, yet 'show="*"' What this does is replace the text with *, like a password box :D
  23. nameE.grid(row=1, column=1) # You know what this does now :D
  24. pwordE.grid(row=2, column=1) # ^^
  25.  
  26. signupButton = Button(roots, text='Signup', command=FSSignup) # This creates the button with the text 'signup', when you click it, the command 'fssignup' will run. which is the def
  27. signupButton.grid(columnspan=2, sticky=W)
  28. roots.mainloop() # This just makes the window keep open, we will destroy it soon
  29.  
  30. def FSSignup():
  31. with open(creds, 'w') as f: # Creates a document using the variable we made at the top.
  32. f.write(nameE.get()) # nameE is the variable we were storing the input to. Tkinter makes us use .get() to get the actual string.
  33. f.write('\n') # Splits the line so both variables are on different lines.
  34. f.write(pwordE.get()) # Same as nameE just with pword var
  35. f.close() # Closes the file
  36.  
  37. roots.destroy() # This will destroy the signup window. :)
  38. Login() # This will move us onto the login definition :D
  39.  
  40. def Login():
  41. global nameEL
  42. global pwordEL # More globals :D
  43. global rootA
  44.  
  45. rootA = Tk() # This now makes a new window.
  46. rootA.title('Login') # This makes the window title 'login'
  47.  
  48. intruction = Label(rootA, text='Please Login\n') # More labels to tell us what they do
  49. intruction.grid(sticky=E) # Blahdy Blah
  50.  
  51. nameL = Label(rootA, text='Username: ') # More labels
  52. pwordL = Label(rootA, text='Password: ') # ^
  53. nameL.grid(row=1, sticky=W)
  54. pwordL.grid(row=2, sticky=W)
  55.  
  56. nameEL = Entry(rootA) # The entry input
  57. pwordEL = Entry(rootA, show='*')
  58. nameEL.grid(row=1, column=1)
  59. pwordEL.grid(row=2, column=1)
  60.  
  61. loginB = Button(rootA, text='Login', command=CheckLogin) # This makes the login button, which will go to the CheckLogin def.
  62. loginB.grid(columnspan=2, sticky=W)
  63.  
  64. rmuser = Button(rootA, text='Delete User', fg='red', command=DelUser) # This makes the deluser button. blah go to the deluser def.
  65. rmuser.grid(columnspan=2, sticky=W)
  66. rootA.mainloop()
  67.  
  68. def CheckLogin():
  69. with open(creds) as f:
  70. data = f.readlines() # This takes the entire document we put the info into and puts it into the data variable
  71. uname = data[0].rstrip() # Data[0], 0 is the first line, 1 is the second and so on.
  72. pword = data[1].rstrip() # Using .rstrip() will remove the \n (new line) word from before when we input it
  73.  
  74. if nameEL.get() == uname and pwordEL.get() == pword: # Checks to see if you entered the correct data.
  75. r = Tk() # Opens new window
  76. r.title(':D')
  77. r.geometry('150x50') # Makes the window a certain size
  78. rlbl = Label(r, text='\n[+] Logged In') # "logged in" label
  79. rlbl.pack() # Pack is like .grid(), just different
  80. r.mainloop()
  81. else:
  82. r = Tk()
  83. r.title('D:')
  84. r.geometry('150x50')
  85. rlbl = Label(r, text='\n[!] Invalid Login')
  86. rlbl.pack()
  87. r.mainloop()
  88.  
  89. def DelUser():
  90. os.remove(creds) # Removes the file
  91. rootA.destroy() # Destroys the login window
  92. Signup() # And goes back to the start!
  93.  
  94. if os.path.isfile(creds):
  95. Login()
  96. else: # This if else statement checks to see if the file exists. If it does it will go to Login, if not it will go to Signup :)
  97. Signup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement