I'm using python package Watchdog to monitor a file for changes, and want to launch a GUI when the file is modified. Currently when I'm initiating the GUI inside the custom handler, the GUI window freezes. Here's a rough idea of what my code looks like:
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
window = tk.Tk()
window.title("app")
window.mainloop()
if __name__ == "__main__":
path = sys.argv[1] if len(sys.argv) > 1 else '.'
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Any help on this would be greatly appreciated! Thanks!