Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- listen_rfid
- from threading import Thread
- t = Thread(target=self.listen_rfid)
- t.daemon = True # this line tells the thread to quit if the GUI (master thread) quits.
- t.start()
- try:
- # python 2
- import Tkinter as tk
- import ttk
- except ImportError:
- # python 3
- import tkinter as tk
- from tkinter import ttk
- self.tk = tk.Tk()
- self.frame = tk.Frame(self.tk)
- #!/usr/bin/env python3
- import sys
- import select
- import MySQLdb
- if sys.version_info[0] == 2:
- from Tkinter import *
- import Tkinter as ttk
- else:
- from tkinter import *
- import tkinter as ttk
- class Fullscreen_Window:
- def __init__(self):
- self.tk = Tk()
- self.frame = Frame(self.tk)
- self.frame.pack()
- ttk.Button(self.tk, text="hello world").pack()
- self.tk.attributes('-zoomed', True)
- self.state = False
- self.tk.bind("<F11>", self.toggle_fullscreen)
- self.tk.bind("<Escape>", self.end_fullscreen)
- print("init running")
- # Schedule self.listen_rfid to run after the mainloop starts
- self.tk.after(0, self.listen_rfid)
- def toggle_fullscreen(self, event=None):
- self.state = not self.state # Just toggling the boolean
- self.tk.attributes("-fullscreen", self.state)
- print("Toggling")
- return "break"
- def end_fullscreen(self, event=None):
- self.state = False
- self.tk.attributes("-fullscreen", False)
- return "break"
- def listen_rfid(self):
- print("Main loop running")
- dbHost = 'localhost'
- dbName = 'python'
- dbUser = 'python'
- dbPass = 'PASSWORD'
- dbConnection = MySQLdb.connect(host=dbHost, user=dbUser, passwd=dbPass, db=dbName)
- cur = dbConnection.cursor(MySQLdb.cursors.DictCursor)
- # readline is blocking so check that there is input
- # before attempting to read it.
- r, w, x = select.select([sys.stdin], [], [], 0)
- if r:
- # There is available input, so read a line.
- RFID_input = sys.stdin.readline().rstrip()
- cur.execute("SELECT * FROM access_list WHERE rfid_code = '%s'" % (RFID_input))
- if cur.rowcount != 1:
- print("ACCESS DENIED")
- else:
- user_info = cur.fetchone()
- print("Welcome %s!!" % (user_info['name']))
- # keep running every 500 milliseconds for as long as
- # the mainloop is active.
- self.tk.after(500, self.listen_rfid)
- if __name__ == '__main__':
- w = Fullscreen_Window()
- w.tk.mainloop()
Add Comment
Please, Sign In to add comment