Guest User

Untitled

a guest
Jan 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. import gtk
  5.  
  6. class LoginWindow(gtk.Window):
  7. def __init__(self):
  8. gtk.Window.__init__(self)
  9.  
  10. self.connect("destroy", gtk.main_quit)
  11. self.set_title("Login")
  12.  
  13. self.login_label = gtk.Label("Login please")
  14.  
  15. # User Input
  16. self.user_input = gtk.Entry()
  17. self.user_input.connect("activate", self.do_login)
  18.  
  19. # Password Input
  20. self.pass_input = gtk.Entry()
  21. self.pass_input.set_visibility(False)
  22. self.pass_input.connect("activate", self.do_login)
  23.  
  24. self.login_hbox = gtk.HBox()
  25. self.login_hbox.pack_start(self.user_input)
  26. self.login_hbox.pack_start(self.pass_input)
  27.  
  28. self.main_vbox = gtk.VBox()
  29. self.main_vbox.pack_start(self.login_label)
  30. self.main_vbox.pack_start(self.login_hbox)
  31.  
  32. self.add(self.main_vbox)
  33. self.show_all()
  34.  
  35. def do_login(self, *args):
  36. username = self.user_input.get_text()
  37. password = self.pass_input.get_text()
  38.  
  39. if username == "admin" and password == "admin":
  40. self.login_label.set_text("Logged in")
  41. self.user_input.hide()
  42. self.pass_input.hide()
  43. else:
  44. self.login_label.set_text("Invalid username or password")
  45.  
  46. if __name__ == "__main__":
  47. win = LoginWindow()
  48. gtk.main()
Add Comment
Please, Sign In to add comment