I'm writing a Python programme which listens for RFID input and only runs if a valid token is presented. The programme also has a GUI which I'm wanting to build using TkInter.
Both parts of the puzzle work fine in isolation, however as it stands I seem to be able to choose one or the other - but not both! I can draw my TkInter window fine, however if I call the function to start listening for the RFID input then whilst that bit runs OK and works... there's no GUI.
Code is below. You can see my debugging efforts so far with my printouts to the terminal...
#!/usr/bin/env python3 import sys 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") self.listen_rfid() # Commenting this out makes the GUI appear, uncommenting means no GUI :( 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) with open('/dev/stdin', 'r') as tty: while True: RFID_input = tty.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'])) tty.close() listen_rfid() if __name__ == '__main__': w = Fullscreen_Window() w.tk.mainloop()
I'm sure it's something really simple but as I'm a Python/TkInter n00b it's beaten me and I'm all done Googling. Any help gratefully received :)
listen_rfid
thatFulscreen_Window.listen_rfid
calls defined? Should that beself.listen_rfid
? – FamousJameousself.listen_rfid
? – FamousJameous