I am new to programming in python, and I need to make a Tkinter menu that has 3 buttons, each one should run a specific python script when pressed, these scripts were done with opencv, they perform face recognition, lets call them find1.py, find2.py and detect.py. find1 and find2 are irrelevant to my issue. Detect.py searches for a specific face in a video, if it does not recognize the face it will edit a .txt file and write "0" in it, if it does recognize it, it will write a "1". My Tkinter menu needs to have the 3 buttons (find1, find2 and Detect) in the upper part of the window and a button containing a "green.png" image in the center-bottom, if I press the button that runs Detect.py the it should run the program and check constantly the .txt file, in case it reads a "1" the "green.png" image will stay, however if it reads a "0" the image of the button has to change to a "red.png" image.
I did manage to make the buttons run my scripts using os.system, however I dont believe I have the knowledge to perform the image swap and the monitoring of the .txt file, I followed a couple of posts of people trying to open a file and read its contents but I could not manage to apply that to my script, I will be very thankful if somebody could tell me if I am writing my scripts properly and if you could show me how to perform the image swap and text monitoring.
from tkinter import *
import os
from PIL import Image,ImageTk
window = Tk()
window.geometry('350x150')
window.title('OPENCV2 MENU')
def run():
os.system('python3 find1.py')
btn1 = Button(window, text="find1", bg="gray", fg="white",command=run)
btn1.grid(row = 0, column = 1)
def run1():
os.system('python3 find2.py')
btn2 = Button(window, text="find2", bg="gray", fg="white",command=run1)
btn2.grid(row = 0, column = 2)
def run2():
os.system('python3 Detect.py')
btn3 = Button(window, text="detect", bg="gray", fg="white",command=run2)
btn3.grid(row = 0, column = 3)
with open('access.txt', 'r') as docu:
val = int(docu.read().strip())
if val == 0:
photo = Image.open(r"red.png")
else:
photo = Image.open(r"green.png")
image2 = photo.resize((100,110),Image.ANTIALIAS)
photo2 =ImageTk.PhotoImage(image2)
Button(window, text = 'Click Me', image = photo2).grid(row =2, column =2)
window.mainloop()