From 034cb8059d8c78b7f3b48a6c4b331303264491d3 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Tue, 11 Feb 2025 16:20:30 -0800 Subject: [PATCH] refactor: Improve tkinter directory selection in Streamlit app --- src/streamlit_app.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/streamlit_app.py b/src/streamlit_app.py index 027e7f9..d00f7f0 100644 --- a/src/streamlit_app.py +++ b/src/streamlit_app.py @@ -213,7 +213,15 @@ with col1: root = tk.Tk() root.withdraw() root.wm_attributes('-topmost', 1) - path = filedialog.askdirectory(title="Select Source Directory") + root.after(10) # Add a small delay + # Create and run the main loop in a way that doesn't block + path = None + def select_dir(): + nonlocal path + path = filedialog.askdirectory(title="Select Source Directory") + root.quit() + root.after(20, select_dir) + root.mainloop() if path: st.session_state['source_dir_selected'] = path st.rerun() @@ -262,7 +270,15 @@ with col1: root = tk.Tk() root.withdraw() root.wm_attributes('-topmost', 1) - path = filedialog.askdirectory(title="Select Destination Directory") + root.after(10) # Add a small delay + # Create and run the main loop in a way that doesn't block + path = None + def select_dir(): + nonlocal path + path = filedialog.askdirectory(title="Select Destination Directory") + root.quit() + root.after(20, select_dir) + root.mainloop() if path: st.session_state['dest_dir_selected'] = path st.rerun()