I am a newb and I have a small script that uses guizero to create a small app that reads a rfid tag and activates door lock. The problem I am having is, when the power goes off and the raspberry pi reboots. the script launches but I have to manually click in the texts box before it will start working. how can I have it automatically set focus on the textbox when it launches? thanks Mark
Here is code, I found this project online and modified some to work for me.
from gpiozero import LED, Buzzer
from guizero import App, Box, Text, TextBox, warn
import gpiozero
import csv
RELAY_PIN = 17
led8 = LED(5)
led9 = LED(6)
relay= gpiozero.OutputDevice(RELAY_PIN,active_high=False, initial_value=False)
def clearDisplay():
print("Clear display")
rfidStatus.value = "—"
rfidText.value = ""
led8.off()
led9.off()
relay.off()
rfidStatus.repeat(1000, checkRFidTag)
def checkRFidTag():
tagId = rfidText.value
if tagId != "":
RFidRegistered = False
print(tagId)
with open("Database.csv") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row["RFid"] == tagId:
RFidRegistered = True
print("Welcome " + row["User"])
rfidStatus.value = "Welcome " + row["User"]
led8.on()
relay.toggle()
rfidStatus.after(5000, clearDisplay)
if RFidRegistered == False:
print("RFid tag is not registered")
rfidStatus.value = "RFid tag is not registered"
led9.on()
rfidStatus.after(3000, clearDisplay)
rfidStatus.cancel(checkRFidTag)
app = App(title="RFID EM4100 Simple GUI", width=350, height=150, layout="auto")
instructionText = Text(app, text="Click on the text button below\nand scan your RFid tag.")
rfidText = TextBox(app,text="")
rfidStatus = Text(app, text="—")
rfidStatus.repeat(1000, checkRFidTag)
#designBy = Text(app, text="Design by Idris – Cytron Technologies", align="bottom")
app.display()
view