Guest User

Untitled

a guest
Dec 17th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. listen_rfid
  2.  
  3. from threading import Thread
  4. t = Thread(target=self.listen_rfid)
  5. t.daemon = True # this line tells the thread to quit if the GUI (master thread) quits.
  6. t.start()
  7.  
  8. try:
  9. # python 2
  10. import Tkinter as tk
  11. import ttk
  12. except ImportError:
  13. # python 3
  14. import tkinter as tk
  15. from tkinter import ttk
  16.  
  17. self.tk = tk.Tk()
  18. self.frame = tk.Frame(self.tk)
  19.  
  20. #!/usr/bin/env python3
  21. import sys
  22. import select
  23. import MySQLdb
  24.  
  25. if sys.version_info[0] == 2:
  26. from Tkinter import *
  27. import Tkinter as ttk
  28. else:
  29. from tkinter import *
  30. import tkinter as ttk
  31.  
  32. class Fullscreen_Window:
  33. def __init__(self):
  34. self.tk = Tk()
  35. self.frame = Frame(self.tk)
  36. self.frame.pack()
  37. ttk.Button(self.tk, text="hello world").pack()
  38.  
  39. self.tk.attributes('-zoomed', True)
  40. self.state = False
  41. self.tk.bind("<F11>", self.toggle_fullscreen)
  42. self.tk.bind("<Escape>", self.end_fullscreen)
  43.  
  44. print("init running")
  45. # Schedule self.listen_rfid to run after the mainloop starts
  46. self.tk.after(0, self.listen_rfid)
  47.  
  48. def toggle_fullscreen(self, event=None):
  49. self.state = not self.state # Just toggling the boolean
  50. self.tk.attributes("-fullscreen", self.state)
  51. print("Toggling")
  52. return "break"
  53.  
  54. def end_fullscreen(self, event=None):
  55. self.state = False
  56. self.tk.attributes("-fullscreen", False)
  57. return "break"
  58.  
  59. def listen_rfid(self):
  60. print("Main loop running")
  61. dbHost = 'localhost'
  62. dbName = 'python'
  63. dbUser = 'python'
  64. dbPass = 'PASSWORD'
  65.  
  66. dbConnection = MySQLdb.connect(host=dbHost, user=dbUser, passwd=dbPass, db=dbName)
  67. cur = dbConnection.cursor(MySQLdb.cursors.DictCursor)
  68.  
  69. # readline is blocking so check that there is input
  70. # before attempting to read it.
  71. r, w, x = select.select([sys.stdin], [], [], 0)
  72. if r:
  73. # There is available input, so read a line.
  74. RFID_input = sys.stdin.readline().rstrip()
  75. cur.execute("SELECT * FROM access_list WHERE rfid_code = '%s'" % (RFID_input))
  76.  
  77. if cur.rowcount != 1:
  78. print("ACCESS DENIED")
  79. else:
  80. user_info = cur.fetchone()
  81. print("Welcome %s!!" % (user_info['name']))
  82.  
  83. # keep running every 500 milliseconds for as long as
  84. # the mainloop is active.
  85. self.tk.after(500, self.listen_rfid)
  86.  
  87. if __name__ == '__main__':
  88. w = Fullscreen_Window()
  89. w.tk.mainloop()
Add Comment
Please, Sign In to add comment